使用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的更多相关文章

  1. iOS.FBTweak

    FBTweak的源码分析 1. FBTweak提供了以下功能 A): 可以动态的修改某个变量的值,这些变量的类型包括: ... B): 可以以plist的形式将Tweak以key-value的形式进行 ...

随机推荐

  1. Innosetup的状态页面和向导页面解释

    1.安装: CurStepChanged所对应的全部状态:3种 1.1. CurStep=ssInstall         --是在程序实际安装前(所有配置都准备好了)     1.2. CurSt ...

  2. Memcached理解笔记4---应对高并发攻击

    近半个月过得很痛苦,主要是产品上线后,引来无数机器用户恶意攻击,不停的刷新产品各个服务入口,制造垃圾数据,消耗资源.他们的最好成绩,1秒钟可以并发6次,赶在Database入库前,Cache进行Mis ...

  3. sql 等额本息

    /* 等额本息计算还款额 a 贷款总额 b 月利率 m 贷款月数 */ execute block returns (result double precision) as declare a ; - ...

  4. c#基础学习(0806)之StringBuilder的使用

    以前字符串的拼接基本都是用string来完成的,从来没有考虑过性能或者速度的问题,自从学习了StringBuilder之后才发现两者的差距有多大,当然,数据量比较小的时候,用string还是挺方便的, ...

  5. 2 字节的 UTF-8 序列的字节 2 无效 解决方法

    2 字节的 UTF-8 序列的字节 2 无效 解决方法: 用记事本打开xml文件,另存为 编码 选择 UTF-8,保存替换掉之前的文件,解决问题

  6. Python中类的属性的访问控制

    因为自己是做.NET的,之前有学习过Python,喜欢这门语言的很多特性,最近又不时看了一会儿,将自己的感受分享给大家,其中也难免会用C#的角度看Python的语法,主要还是讲下Python中类中对属 ...

  7. 我在项目中运用 IOC(依赖注入)--入门篇

    之前就听同事说过依赖注入(dependency injection).控制反转(Inversion of Control).起初听的是一头雾水,试着在项目中运用了几次,总算明白了一些,抛砖引玉,与大家 ...

  8. 设计模式学习——抽象工厂模式(Abstract Factory Pattern)

    现有一批装备(产品),分为不同的部位(上装.下装)与不同的等级(lv1.lv2).又有不同lv的工厂,只生产对应lv的全套装备. 代码实现上...本次写得比较偷懒,函数实现都写在头文件了.... 有些 ...

  9. WinForm中使用CrystalReport水晶报表——基础,分组统计,自定义数据源

    开篇 本篇文章主要是帮助刚开始接触CrystalReport报表的新手提供一个循序渐进的教程.该教程主要分为三个部分1)CrystalReport的基本使用方法:2)使用CrystalReport对数 ...

  10. koa 中,中间件异步与同步的相关问题

    同步中间件很容易理解,如以下代码: const Router = require('koa-router') , koa = new Router({ prefix: '/koa' }) , fs = ...