UIEvent - 3
2015-08-31 17:23
246 查看
对上一节的例子做一些修改:
LBEventTestView.h
LBEventTestView.m
调用的视图控制器:
如图:
分别点击这4个区域然后参考上文的文章理解。
挑选一个点击区域1和区域4来讲解:
区域1:
解析:点击白色区域1,开始遍历子视图的时候发现点击点不在RED红色区域(因为return的都是NO),就不继续调用别的在RED相关的子视图了。那一定会问为什么会调用了两次? 如图上所示是两次,看看文档的方法描述:
就是这个方法搞的鬼,它是用递归式的调用。所以调用的是多次,具体是多少次,我还真不敢说。(因为不懂哈哈)
区域4:
可以清楚看到,yellow视图同为RED的子视图,是完全不会去调用的。连Return NO的机会都没有。慢慢的似乎有一点点的规律,上一节的两层视图的结构就会调用2次,这一节的3层视图的结构就会调用6次,我严重怀疑recursively是不是 视图继承层数 H * 2 呢。以后懂了再在这里阐述吧!
LBEventTestView.h
#import <UIKit/UIKit.h> @interface LBEventTestView : UIView @property (nonatomic, strong) NSString* colorString;//增加辨识变量colorString @end
LBEventTestView.m
#import "LBEventTestView.h" @implementation LBEventTestView - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event { NSLog(@"ColorString hitTest : %@, %@", self.colorString, [super hitTest:point withEvent:event]); return [super hitTest:point withEvent:event]; } - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { NSLog(@"ColorString pointInside : %@, %@", self.colorString, [super pointInside:point withEvent:event]? @"YES" : @"NO"); return [super pointInside:point withEvent:event]; } @end
调用的视图控制器:
#import "Masonry.h" #import "LBEventTestView.h" #import "UIEventTestController.h" @implementation UIEventTestController - (void)viewDidLoad { [super viewDidLoad]; //RED LBEventTestView* redView = [[LBEventTestView alloc] init]; redView.colorString = @"RED"; [redView setBackgroundColor:[UIColor redColor]]; [self.view addSubview:redView]; [redView mas_makeConstraints:^(MASConstraintMaker* make){ make.center.mas_equalTo(self.view); make.size.mas_equalTo(CGSizeMake(250, 350)); }]; //YELLOW LBEventTestView* yellow = [LBEventTestView new]; yellow.colorString = @"YELLOW"; [yellow setBackgroundColor:[UIColor yellowColor]]; [redView addSubview:yellow]; [yellow mas_makeConstraints:^(MASConstraintMaker* make){ make.centerX.equalTo(redView); make.size.mas_equalTo(CGSizeMake(100, 80)); make.top.mas_equalTo(redView.mas_top).with.offset(30); }]; //GREEN LBEventTestView* green = [LBEventTestView new]; green.colorString = @"GREEN"; [green setBackgroundColor:[UIColor greenColor]]; [redView addSubview:green]; [green mas_makeConstraints:^(MASConstraintMaker* make){ make.centerX.equalTo(redView); make.size.mas_equalTo(yellow); make.bottom.mas_equalTo(redView.mas_bottom).with.offset(-30); }]; } @end
如图:
分别点击这4个区域然后参考上文的文章理解。
挑选一个点击区域1和区域4来讲解:
区域1:
解析:点击白色区域1,开始遍历子视图的时候发现点击点不在RED红色区域(因为return的都是NO),就不继续调用别的在RED相关的子视图了。那一定会问为什么会调用了两次? 如图上所示是两次,看看文档的方法描述:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; // recursively calls -pointInside:withEvent:. point is in the receiver's coordinate system
就是这个方法搞的鬼,它是用递归式的调用。所以调用的是多次,具体是多少次,我还真不敢说。(因为不懂哈哈)
区域4:
可以清楚看到,yellow视图同为RED的子视图,是完全不会去调用的。连Return NO的机会都没有。慢慢的似乎有一点点的规律,上一节的两层视图的结构就会调用2次,这一节的3层视图的结构就会调用6次,我严重怀疑recursively是不是 视图继承层数 H * 2 呢。以后懂了再在这里阐述吧!
相关文章推荐
- android之UEventObserver分析
- [推荐]Android消息处理机制(Handler、Looper、MessageQueue与Message) Android是消息驱动的,实现消息驱动有几个要素: 消息的表示:Message 消息
- UITabBar的背景颜色属性
- UIEvent - 2
- UITableView的使用和点击每个cell跳转到其他controller优化
- UIAlertView在其他页面快速显示?
- poj 3080 Blue Jeans
- 关于UIBarItem和UINvigationController,UITabBarController关系
- IE7/8当文本模式为杂项"Quirks" 导致JSP页面变样的问题
- r.js 打包压缩文件(依赖require)
- hdoj 4062 Queuing 【矩阵快速幂优化递推公式】
- UITableView-------模型的使用
- 你给我解析清楚,都有了CALayer了,为什么还要UIView
- 用Arduino监控的自动咖啡壶
- Android线程---UI线程和非UI线程之间通信
- UIEvent - 1
- 77 NSMutableURLRequest常用设置 GET和POST比较 发送JSON给服务器
- 阿里DruidDataSource配置(druid)
- 疯狂ios讲义之选择器(UIPickerView)
- 一个实用的android框架(二)—— UI