按钮超过父视图范围无法响应事件的处理方法

2022-11-30  本文已影响0人  EnjoyWT
- (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;  
}  
   override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        var v = super.hitTest(point, with: event)
        if v == nil {
            let tempPoint = self.imageV.convert(point, from: self)
            if self.imageV.bounds.contains(tempPoint){
                v = self.imageV
            }
        }
        return v
    }
上一篇下一篇

猜你喜欢

热点阅读