使用FBTweak
使用FBTweak
https://github.com/facebook/Tweaks
FBTweak是Facebook的一款开源库,用于微调数据而无需我们重复编译跑真机用的,它支持4种类型的cell
- _FBTweakTableViewCellModeBoolean,
- _FBTweakTableViewCellModeInteger,
- _FBTweakTableViewCellModeReal,
- _FBTweakTableViewCellModeString,
用起来还不错,但在实际开发中,我们应该用得很少吧!权当学习开源库使用给大家介绍介绍.
示例源码地址:
http://pan.baidu.com/s/1i3KHQ1B
本人测试时的效果图:
源码:
AppDelegate.m
//
// AppDelegate.m
// Tweak
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "FBTweak.h"
#import "FBTweakShakeWindow.h"
#import "FBTweakInline.h"
#import "FBTweakViewController.h" #import "AppDelegate.h"
#import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[FBTweakShakeWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.rootViewController = [RootViewController new]; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} @end
RootViewController.m
//
// RootViewController.m
// Tweak
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "FBTweak.h"
#import "FBTweakShakeWindow.h"
#import "FBTweakInline.h"
#import "FBTweakViewController.h"
#import "RootViewController.h" // 全局显示的方式
FBTweakAction(@"全局操作", @"显示一个AlertView", @"显示这个AlertView", ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"YouXianMing"
message:@"全局测试1"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"完成", nil];
[alert show];
}); @interface RootViewController ()<FBTweakObserver, FBTweakViewControllerDelegate> { FBTweak *_flipTweak; } @end @implementation RootViewController - (void)addTestButton
{
// 添加一个按钮用来进行微调
UIButton *tweaksButton = [[UIButton alloc] initWithFrame:(CGRect){CGPointZero, CGSizeMake(, )}];
tweaksButton.center = self.view.center;
tweaksButton.layer.borderWidth = 0.5f;
tweaksButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight"
size:.f];
[tweaksButton setTitle:@"YouXianMing"
forState:UIControlStateNormal];
[tweaksButton setTitleColor:[UIColor blackColor]
forState:UIControlStateNormal];
[tweaksButton addTarget:self
action:@selector(buttonTapped)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tweaksButton];
} - (void)viewDidLoad
{
[super viewDidLoad]; // 添加微调按钮
[self addTestButton]; // 初始化一个测试用label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
label.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:.f];
label.textColor = [UIColor redColor];
[self.view addSubview:label]; // 初始化一个测试用view
UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
showView.backgroundColor = [UIColor redColor];
[self.view addSubview:showView];
UITapGestureRecognizer *tap = \
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapGesture:)];
[showView addGestureRecognizer:tap]; // 注册一个微调值的方式(后面通过方法FBTweakValue来将值取出来)
FBTweak *animationDurationTweak = \
FBTweakInline(@"UI控件", @"某个View", @"动画时间", 1.0, 0.1, 7.0);
animationDurationTweak.stepValue = [NSNumber numberWithFloat:0.1f]; // 绑定属性的方式
FBTweakBind(label, text, @"UI控件", @"某个Label", @"字符串", @"YouXianMing");
FBTweakBind(label, alpha, @"UI控件", @"某个Label", @"透明度", 1.0, 0.0, 1.0); // 走代理的方式
_flipTweak = FBTweakInline(@"视图视图控制器", @"效果", @"翻转", NO);
[_flipTweak addObserver:self];
} - (void)buttonTapped
{
FBTweakViewController *viewController = \
[[FBTweakViewController alloc] initWithStore:[FBTweakStore sharedInstance]];
viewController.tweaksDelegate = self; [self presentViewController:viewController
animated:YES
completion:NULL];
} - (void)tapGesture:(UITapGestureRecognizer *)tap
{
// 从注册的值中取出来
NSTimeInterval duration = \
FBTweakValue(@"UI控件", @"某个View", @"动画时间", 1.0, 0.1, 7.0); static BOOL flag = YES;
if (flag)
{
[UIView animateWithDuration:duration animations:^{
tap.view.frame = CGRectMake(, , , );
}];
}
else
{
[UIView animateWithDuration:duration animations:^{
tap.view.frame = CGRectMake(, , , );
}];
} flag = !flag;
} #pragma mark - FBTweak的两个代理方法
- (void)tweakDidChange:(FBTweak *)tweak
{
if (tweak == _flipTweak)
{
self.view.layer.sublayerTransform = \
CATransform3DMakeScale(1.0, [_flipTweak.currentValue boolValue] ? -1.0 : 1.0, 1.0);
}
} - (void)tweakViewControllerPressedDone:(FBTweakViewController *)tweakViewController
{
// 推出控制器
[tweakViewController dismissViewControllerAnimated:YES
completion:nil];
} @end
几个值得注意的地方:
使用FBTweak的更多相关文章
- iOS.FBTweak
FBTweak的源码分析 1. FBTweak提供了以下功能 A): 可以动态的修改某个变量的值,这些变量的类型包括: ... B): 可以以plist的形式将Tweak以key-value的形式进行 ...
随机推荐
- MySQL命令行导入导出数据
参考:http://www.cnblogs.com/xcxc/archive/2013/01/30/2882840.html 这篇文章写得非常好,又简洁,而且深入浅出,排版也非常好看,不会像网上的只是 ...
- 开发小技巧1——Logger
开发小技巧1——Logger 在项目中加入静态Logger类,用于捕获并记录程序的进度.错误信息: public static class Logger { public static void ...
- rails中params[:id]与params["id"]分析
写这个帖子的缘由是因为在页面参数传到rails的controller时用params[:]和params[""]都可以取到值: [1] pry(#<BooksControll ...
- HTTP协议以及HTTP请求中8种请求方法
HTTP协议以及HTTP请求中8种请求方法 什么是协议? 协议,是指通信的双方,在通信流程或内容格式上,共同遵守的标准. 什么是http协议? http协议,是互联网中最常见的网络通信标准. http ...
- C#语法之委托和事件
从大学就开始做C#这块,也做C#几年了,最近又从ios转回.Net,继续做C#,之前也没有写博客的习惯,写博客也是从我做ios的时候开始的,现在既然又做回了.net,那就写点关于.Net的博客,可能在 ...
- .Net调用Java端带有WS-Security支持的Web Service【亲测通过】
做了几年的开发,今天终于鼓起勇气开通了博客园.平时都是找各种大牛,看他们的分享博客的解决BUG.从今天起,我也开始分享我学习之路.还望大家多多支持! 最近收到一个采用Axis2实现的WebServic ...
- Android 操作Sqlite
首先要用一个类来继承SQLiteOpenHelper,并必须实现 public DatabaseHelper(Context context, String name, CursorFactory f ...
- 什么是memcached?
缓存是一种常驻与内存的内存数据库,内存的读取速度远远快于程序在磁盘读取数据的速度.我们在设计程序的时候常常会考虑使用缓存,将经常访问的数据放到内存上面这样可以提高访问数据的速度,同时可以降低磁盘或数据 ...
- 线程5--GCD简介
/******************************************************/ 同步函数 (1)并发队列:不会开线程 (2)串行队列:不会开线程 异步函数 ...
- Java多态-如何理解父类引用指向子类对象
java多态,如何理解父类引用指向子类对象 要理解多态性,首先要知道什么是“向上转型”. 我定义了一个子类Cat,它继承了Animal类,那么后者就是前者是父类.我可以通过 Cat c = new ...