RAC初学记录
个人记录,方便查阅
场景 1.用户登录,登录按钮需账号密码同时满足某个条件才能点击
NSArray *signals = @[self.phoneTextField.rac_textSignal, self.passwordTextField.rac_textSignal];
RAC(self.loginButton, enabled) = [RACSignal combineLatest:signals reduce:^(NSString *username, NSString *password) {
return@(username.length > 0 && password.length >= 6);
}];
场景 2. 登录密码框右边按钮,点击可查看密码,再次点击变为******
@weakify(self);
[[[self.securityButton rac_signalForControlEvents:UIControlEventTouchUpInside] map:^id(UIButton *button) {
button.selected =!button.selected;
return @(button.selected);
}] subscribeNext:^(idx) {
@strongify(self);
self.passwordTextField.secureTextEntry =![xboolValue];
}];
场景 3. 获取验证码60S倒计时,倒计时期间按钮为不可点状态
```
- (RACSignal *)resendVerificationCode {
staticconstNSIntegertimes = 60;
RACSignal *timer = [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] map:^id(id value) {
return nil;
}] startWith:nil];
NSMutableArray *numbers = [[NSMutableArrayalloc] initWithCapacity:times];
for (inti = times;
i >= 0;
i--) {
[numbersaddObject:@(i)];
}
return [[[numbers.rac_sequence.signalzipWith:timer] map:^id(RACTuple*tuple) {
NSNumber *number = tuple.first;
NSIntegercount = number.integerValue;
if (count ==0) {
returnRACTuplePack(@"获取验证码",@YES);
} else {
NSString *title = [NSStringstringWithFormat:@"重新获取(%@)", number];
return RACTuplePack(title,@NO);
}
}] takeUntil:self.rac_willDeallocSignal];
}
- (void)setupCodeButton {
@weakify(self);
[[[[[[self.codeButton rac_signalForControlEvents:UIControlEventTouchUpInside] map:^id(id value) {
@strongify(self);
if([self.bankIDTextField.textisEmptyString]) {
[SVProgressHUD showErrorWithStatus:@"银行卡号不能为空!"];
return nil;
} else {
//if (![self.bankIDTextField.text isValidBankCardNumber]) {
//[SVProgressHUD showErrorWithStatus:@"请输入正确的银行卡号!"];
//return nil;
//}
}
if([self.mobileTextField.textisEmptyString]) {
[SVProgressHUD showErrorWithStatus:@"手机号码不能为空!"];
return nil;
} else {
if (![self.mobileTextField.textisValidMobileNumber]) {
[SVProgressHUD showErrorWithStatus:@"请输入有效的手机号码!"];
return nil;
}
}
[selfrequestCode];
return [self resendVerificationCode];
}] startWith:nil] switchToLatest] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(RACTuple *tuple) {
@strongify(self);
dispatch_async(dispatch_get_main_queue(), ^{
[self.codeButton setTitle:tuple.first forState:UIControlStateNormal];
[self.codeButtonsetEnabled:[tuple.secondboolValue]];
});
}];
}
```
【RAC初学记录】不喜勿喷,个人记录方便翻阅,后续如有用到更多场景功能会添加
推荐阅读
- 20170612时间和注意力开销记录
- 漫画初学者如何学习漫画背景的透视画法(这篇教程请收藏好了!)
- 【剽悍读书营成长记录】2018年我收获了什么|【剽悍读书营成长记录】2018年我收获了什么 3357-小松
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 课后分享记录
- Unity和Android通信系列文章2——扩展UnityPlayerActivity
- oracle|oracle java jdk install
- 感赏15+投射
- LeetCode(03)Longest|LeetCode(03)Longest Substring Without Repeating Characters
- Day5+5组+小鹿#写手账,就是记录你一生的帐