iOS 子视图超过了父视图没法响应事件

当按钮超过了父视图范围,点击是没有反应的。由于消息的传递是从最下层的父视图开始调用hittest方法code

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {  
    UIView *view = [super hitTest:point withEvent:event];  
    return view;  
}

须要重写这个方法it

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {  
    UIView *view = [super hitTest:point withEvent:event];  
    if (view == nil) {  
    CGPoint tempoint = [btn convertPoint:point fromView:self];  
        if (CGRectContainsPoint(btn.bounds, tempoint))   
    {  
           view = btn;  
        }  
     }             
    return view;  
}
相关文章
相关标签/搜索