///各种机制转信号///
1.UI事件
[self.logInButton rac_signalForControlEvents:UIControlEventTouchUpInside]
2.Delegate回调
[self rac_signalForSelector:@selector(flickrAPIRequest:didCompleteWithResponse:) fromProtocol:@protocol(OFFlickrAPIRequestDelegate)];
3.Notificaiton
[NSNotificationCenter.defaultCenter rac_addObserverForName:UserDidLogOutNotification object:nil]
4.KVO观察
[RACObserve(self, username)]
5.Target-Action
[self rac_signalForSelector:@selector(didChangeValueForKey:)]
常用情景//
6.AlertView
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Alert" delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:@"NO", nil]; [[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *indexNumber) { if ([indexNumber intValue] == 1) { NSLog(@"you touched NO"); } else { NSLog(@"you touched YES"); } }]; [alertView show];
7.Gesture
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init]; tapGesture.numberOfTapsRequired = 2; [[tapGesture rac_gestureSignal] subscribeNext:^(id x) { [self.viewModel.likeCommand execute:nil]; }];