MUKit系列-MUSignal(信号事件)
2018-05-22 本文已影响243人
mu_无与伦比
MUKit系列包含但不限于以下框架。
MUTableViewManager pod 'MUKit/TableViewManager'
MUNetworking pod 'MUKit/Networking'
MUNavigation pod 'MUKit/Navigation'
MUSignal pod 'MUKit/Signal'
MUEPaymentManager pod 'MUKit/EPaymentManager'
MUShared pod 'MUKit/Shared'
MUCarousel pod 'MUKit/Carousel'
MUEncryption pod 'MUKit/Encryption'
MUCollectionViewManager pod 'MUKit/CollectionViewManager'
MUPopupController pod 'MUKit/PopupController'
MUPaperView pod 'MUKit/PaperView'
详细注释和案例稍后逐步更新.......
MUSingal(解耦的框架,类似于Route)原理
通过runtime和Responder Chain(响应链)动态获取控件的属性名称并执行对应的响应方法。该框架并没有截取原生事件的响应链,而是另外增加了一条响应链.支持纯代码和xib. Signal响应方法的优先级为:view(控件所在的view)>cell(控件所在的UITableViewCell或者UICollectionViewCell)>UIViewController(控件属于的控制器),即Signal响应方法有且只有一个执行.UIViewController是Signal默认实现响应方法的对象。
传统的事件实现方式:
UIButton *button = [UIButton new];
[button addTarget:self action:@selector(clickedButton:) forControlEvents:UIControlEventTouchUpInside];
UIView *view = [UIView new];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clicked:)];
[view addGestureRecognizer:gesture];
有了MUSignal,无需再写烦人的addTarget:action:forControlEvents:和[UITapGestureRecognizer alloc]initWithTarget:action:;
你需要做的只有一步,在你需要的地方实现
Click_MUSignal(SignalName){//SignalName是需要触发事件的控件的属性名称。支持xib和纯代码
//在这里书写控件触发事件后对应的逻辑即可
}
MUSignal事件实现方式
![](https://img.haomeiwen.com/i451899/5419a9a2d93ad30e.gif)
只需要在view、cell或者controller实现对应的响应方法即可。
完整的事例代码:
Github:https://github.com/Jeykit/MUKit
购物车案例:https://www.jianshu.com/p/3562dee4ab9f
MUKit系列
MUTableViewManager(MVVM Tableview):[https://www.jianshu.com/p/fd969f95e1e9]
MUNetworking(网络框架):https://www.jianshu.com/p/bca6652fea9a
MUNavigation(导航框架):https://www.jianshu.com/p/2275bb93a6dd