Target-Action示例代码如下:
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(20,20,50,50)]; btn.backgroundColor = [UIColor redColor]; btn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) { NSLog(@"按钮被点击!!"); return [RACSignal empty]; }];
输出: 2016-05-10 14:51:36.866 testARC[9948:3012689] 按钮被点击!!
KVO
[RACObserve(self,username) subscribeNext:^(NSString *newName) { NSLog(@"%@",newName); }];
Notification示例代码如下
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UITextFieldTextDidBeginEditingNotification object:self.emailTextField] subscribeNext:^(id x) { [self.emailImageView animate]; self.emailImageView.image = [UIImage imageNamed:@"icon-mail-active"]; self.emailTextField.background = [UIImage imageNamed:@"input-outline-active"]; }]; [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UITextFieldTextDidEndEditingNotification object:self.emailTextField] subscribeNext:^(id x) { self.emailTextField.background = [UIImage imageNamed:@"input-outline"]; self.emailImageView.image = [UIImage imageNamed:@"icon-mail"]; }];原文链接:https://www.f2er.com/react/306801.html