面试题

2020-03-05  本文已影响0人  ricefun

响应链:

用户点击屏幕产生事件 -> UIApplication 开始事件分发
-> UIWindow-> Subviews
UIWindow的子视图会内部递归调用

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

如果上面的方法返回视图就会调用这个方法

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    
    NSLog(@"%@ -- pointInside",self.class);
    CGRect bounds = self.bounds;
    //若原热区小于200x200,则放大热区,否则保持原大小不变
    //一般热区范围为40x40 ,此处200是为了便于检测
    CGFloat widthDelta = MAX(200 - bounds.size.width, 0);
    CGFloat heightDelta = MAX(200 - bounds.size.height, 0);
    bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);
    return CGRectContainsPoint(bounds, point);
}

响应链事件是由上至下的;触摸事件是由由下至上的;

分类关联对象

weak 如何自动置为nil

上一篇 下一篇

猜你喜欢

热点阅读