iOS开发那些事

【iOS】超出父视图的子视图如何响应事件?

2017-07-06  本文已影响267人  lever_xu

在父视图添加如下代码。其思路如下:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *view = [super hitTest:point withEvent:event];
    if (view == nil) {
        for (UIView *subView in self.subviews) {
            CGPoint p = [subView convertPoint:point fromView:self];
            if (CGRectContainsPoint(subView.bounds, p)) {
                view = subView;
            }
        }
    }
    return view;
}
上一篇下一篇

猜你喜欢

热点阅读