附上github地址。。https://github.com/zwaldowski/BlocksKit
简单来讲,就是对开发所有控件进行了block 封装,个人觉得没必要去深究,很初级,但是作者写代码的这种精神非常不错,这个地方,对他扩展的uiview进行分析。。其他的能够用到的。。
直接进入正题。使用方法如下
下边分析三方库方法,看看都写了些什么
看他写的方法得出,给UIview 增加类别,作用为增加点击事件。。这里我们点击- (void)bk_whenTapped:(void (^)(void))block; 进入
- (void)bk_whenTouches:(NSUInteger)numberOfTouches tapped:(NSUInteger)numberOfTaps handler:(void (^)(void))block
{
if (!block) return;
UITapGestureRecognizer *gesture = [UITapGestureRecognizer bk_recognizerWithHandler:^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
if (state == UIGestureRecognizerStateRecognized) block();
}];
gesture.numberOfTouchesRequired = numberOfTouches;
gesture.numberOfTapsRequired = numberOfTaps;
[self.gestureRecognizers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:[UITapGestureRecognizer class]]) return;
UITapGestureRecognizer *tap = obj;
BOOL rightTouches = (tap.numberOfTouchesRequired == numberOfTouches);
BOOL rightTaps = (tap.numberOfTapsRequired == numberOfTaps);
if (rightTouches && rightTaps) {
[gesture requireGestureRecognizerToFail:tap];
}
}];
[self addGestureRecognizer:gesture];
}
发现只是添加了 手势点击事件,并将点击事件通过block回调出来。。
真心少。。研究2个小时这个库,总的来说,初级,但是代码规范和经常非常值得学习