ReactiveCocoa 實現 按鈕倒數計時
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title=@"一個閱讀";
[self testOne];
}
-(void)testOne{
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:@"按鈕" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor colorWithRed:58/255.0f green:157/255.0f blue:255/255.0f alpha:1.0f]];
btn.frame= CGRectMake(30,100,100,30);
btn.titleLabel.font = [UIFont systemFontOfSize:18.0f];
btn.layer.cornerRadius = 6;
btn.layer.masksToBounds = YES;
[self.view addSubview:btn];
RACSignal* (^countBlock)(UIButton*) = ^RACSignal*(UIButton* btn){
RACSignal* countsingal = [[[[RACSignal interval:1
onScheduler:[RACScheduler mainThreadScheduler]]
startWith:[NSDatedate]]
scanWithStart:@(10)reduce:^id(NSNumber*running,idnext) {
NSLog(@"running = %@",running);
return@(running.integerValue-1);
}]takeUntilBlock:^BOOL(NSNumber*x) {
returnx.integerValue<0;
}];
returncountsingal;
};
RACSignal* (^CountBlock)(UIButton*) = ^RACSignal*(UIButton* btn){
RACSignal* timeSigal = [countBlock(btn) map:^id(NSNumber* value) {
return [NSString stringWithFormat:@"剩餘%@",value];
}];
btn.enabled=NO;
[btn setBackgroundColor:[UIColor grayColor]];
__blockid saveSubscriber =nil;
RACSignal*resetStringSignal =
[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
saveSubscriber = subscriber;
returnnil;
}];
[timeSigal subscribeCompleted:^{
btn.enabled=YES;
[btn setBackgroundColor:[UIColor colorWithRed:58/255.0f green:157/255.0f blue:255/255.0f alpha:1.0f]];
[saveSubscriber sendNext:@"按鈕"];
[saveSubscriber sendCompleted];
NSLog(@"timer singal complte");
}];
[btnrac_liftSelector:@selector(setTitle:forState:)
withSignals:[RACSignalmerge:@[timeSigal,resetStringSignal]],
[RACSignal return:@(UIControlStateNormal)], nil];
returntimeSigal;
};
btn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
returnCountBlock(btn);
}];
}
相關文章
- Js Jquery 實現的按鈕倒數計時整理JSjQuery
- 【JavaScript】使用js實現傳送郵箱驗證碼,按鈕倒數計時JavaScriptJS
- JavaScript簡訊重發按鈕可用倒數計時JavaScript
- 傳送簡訊驗證,後按鈕倒數計時,防止重新整理倒數計時失效
- 面向Vue新人:寫一個簡單的倒數計時按鈕Vue
- Flutter倒數計時/計時器的實現Flutter
- js實現指定時間倒數計時JS
- jquery實現60秒倒數計時jQuery
- js實現活動倒數計時JS
- JavaScript 前端倒數計時糾偏實現JavaScript前端
- Jquery 實現頁面倒數計時的功能jQuery
- 利用css變數實現按鈕懸浮效果CSS變數
- 倒數計時
- 直播小程式原始碼,vue實現時間倒數計時原始碼Vue
- JavaFx 實現按鈕防抖Java
- 直播系統原始碼,實現倒數計時,定時任務原始碼
- 微信開發之小程式實現倒數計時
- 直播平臺搭建,計時和倒數計時功能的分別實現
- JavaScript倒數計時JavaScript
- 商城倒數計時
- 線上直播系統原始碼,開屏首頁廣告點選跳過按鈕跳過倒數計時原始碼
- Simple WPF: WPF 實現按鈕的長按,短按功能
- 倒數計時34天
- 倒數計時2天!
- 倒數計時1天
- 倒數計時2天
- CSS3動畫實現3D倒數計時效果CSSS3動畫3D
- PPT 倒數計時時鐘,用 GIF 動畫實現,可直接使用 -- 附 Python 實現程式碼動畫Python
- 倒數計時(天、時、分、秒)
- Android View篇之啟動頁倒數計時動畫的實現AndroidView動畫
- 動畫合成小技巧!CSS 實現動感的倒數計時效果動畫CSS
- android 短視訊開發,依靠Kotlin和Handler實現倒數計時AndroidKotlin
- canvas環形倒數計時Canvas
- 用 bash 倒數計時日期
- Android中handler倒數計時Android
- CountDownTimer使用——android倒數計時Android
- 小程式倒數計時深究
- 點選button倒數計時