作为一名iOS开发者, 你写的每一行代码几乎都是对某些事件的反馈:点击button、接收到网络信息、 一个属性的改变(通过KVO监测) 或者 通过CoreLocation监听用户所在位置的变化 以上等等都是很好的例子。然而,这些事件都有不同的编码方式,如: action、delegate、KVO、回调等。ReactiveCocoa为事件定义了标准的接口,从而可以使用一些基本工具来更容易的连接、过滤和组合。
UIControl+BlocksKit 刚开始以为实现action的方法也是链式编程的一部分 blockskit 确实还是不错,
- (id)initWithHandler:(void (^)(id sender))handler forControlEvents:(UIControlEvents)controlEvents;
@property (nonatomic) UIControlEvents controlEvents;
@property (nonatomic, copy) void (^handler)(id sender);
block的封装 在方法的使用中 解决一些问题 项目中也使用了不少
[self.closeButton bk_addEventHandler:^(id sender) {
[self resignTitleResponder];
// [self closeAction];
[self.navigationController popViewControllerAnimated:YES];
} forControlEvents:UIControlEventTouchUpInside];
[self.locationButton bk_addEventHandler:^(id sender) {
[self resignTitleResponder];
[self.store openLocation:^(NSString *title) {
[self.locationButton setTitle:title forState:UIControlStateNormal];
}];
} forControlEvents:UIControlEventTouchUpInside];
[self.coverImageView setImageWithUrl:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"addPictureBgImage"] tapBlock:^(id obj) {
[self resignTitleResponder];
[self uploadHeaderImage];
}];
- (void)uploadHeaderImage {
if (!self.imagePickerManager) {
self.imagePickerManager = [Vmeet_ImagePickerManager newVmeet_ImagePickerManager];
self.imagePickerManager.imgType = @(UploadImageType_RecruitCover);
}
[self.imagePickerManager showImagePickerWithViewContorller:self allowsEditing:YES singleBlock:^(VmeetImage *image) {
self.uploadImage = image;
self.coverImageView.image = image.image;
} block:^(NSArray<VmeetImage *> *imageModels) {
}];
}