MGEvents
MGEvents 提供了一个极其轻量级的 API,用于键路径观察、UIControl 事件处理以及观察和触发自定义事件。
CocoaPods 配置
pod 'MGEvents'
示例
#import <MGEvents/MGEvents.h>
键路径观察
[box onChangeOf:@"selected" do:^{
NSLog(@"the new selected value is: %d", box.selected);
}];
控制事件观察
[button onControlEvent:UIControlEventTouchUpInside do:^{
NSLog(@"i've been touched up inside. golly.");
}];
或者在 Swift 中
button.onControlEvent(.TouchUpInside) {
print("you touched me!")
}
自定义事件和触发器
[earth on:@"ChangedShape" do:^{
NSLog(@"the earth has changed shape");
}];
然后触发事件
[earth trigger:@"ChangedShape"];
更多选项
查看 API 参考 获取更多详细信息。