使用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的形式进行 ...
随机推荐
- Storm:分布式流式计算框架
Storm是一个分布式的.高容错的实时计算系统.Storm适用的场景: Storm可以用来用来处理源源不断的消息,并将处理之后的结果保存到持久化介质中. 由于Storm的处理组件都是分布式的,而且处理 ...
- HTTPS 接入优化建议
随着网络安全的普及成为共识,部署SSL证书完成HTTPS加密的站点 也随之增多.HTTPS加密能够带来的对身份验证及信息加密等诸多好处,不过想要HTTPS协议发挥更加完美的作用也需要开发者在相应环 ...
- Beta阶段——Scrum 冲刺博客第一天
一.当天站立式会议照片一张 二.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中 昨天已完成的工作 今日是Beta冲刺第一天,昨日没有完成的工作 今天计划完成的工作 实现对i ...
- DES对 json 、http参数加密解密算法
网上众多大神们的众多方式实现加解密操作及保障数据安全性.今天无意中发现一篇以 DES加密解密算法.摘抄如下 工具类: import java.security.SecureRandom; import ...
- Golang cron 定时任务使用
1.cron 表达式的基本格式 用过 linux 的应该对 cron 有所了解.linux 中可以通过 crontab -e 来配置定时任务.不过,linux 中的 cron 只能精确到分钟.而我们这 ...
- HTTP报文(面试会问开发时常用的报文头格式)
(本文的解释是完整的,ajax把很多东西封装了) HTTP有两类报文:请求报文和响应报文. HTTP请求报文 一个HTTP请求报文由请求行(request line).请求头部(header).空行和 ...
- Css3盒子尺寸
box-sizing属性 用来改变盒模式中的宽度和高度默认的计算方式. box-sizing: 1.content-box(默认值): 宽度和高度只包含内容区域 2.border-box: 宽度和高度 ...
- Spring 核心组件总结
spring核心组件总结 spring介绍 spring概念 IOC: Inverse Of Control 控制反转 将我们创建对象的方式反转了,以前创建对象是由我们开发人员自己维护,包括依赖注 ...
- Hibernate中查询优化策略
Hibernate查询优化策略 ² 使用延迟加载等方式避免加载多余数据 ² 通过使用连接查询,配置二级缓存.查询缓存等方式减少select语句数目 ² 结合缓存机制,使用iterate()方法减少查询 ...
- MVC,MVP 和 MVVM 的图示(转)
作者: 阮一峰 日期: 2015年2月 1日 转自:http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html 复杂的软件必须有清晰合理的架构,否则 ...