ReactiveCocoa - 简单实用场景

前端之家收集整理的这篇文章主要介绍了ReactiveCocoa - 简单实用场景前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


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"];
}];

猜你在找的React相关文章