美文网首页
button超出父视图无法点击解决

button超出父视图无法点击解决

作者: 米开朗骑騾 | 来源:发表于2019-07-31 17:39 被阅读0次

    参考
    参考

    AlerView类上的一个BaseView上添加按钮 按钮在BaseView之外
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        UIView *view = [super hitTest:point withEvent:event];
        CGPoint tempPoint = [self.closeBtn convertPoint:point fromView:self];
        if ([self.closeBtn pointInside:tempPoint withEvent:event]) {
            NSLog(@"---111111-");
            return self.closeBtn;
        }
        NSLog(@"----222--");
        return view;
    }
    
    // 在自定义UITabBar中重写以下方法,其中self.button就是那个希望被触发点击事件的按钮
    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        UIView *view = [super hitTest:point withEvent:event];
        if (view == nil) {
            // 转换坐标系
            CGPoint newPoint = [self.button convertPoint:point fromView:self];
            // 判断触摸点是否在button上
            if (CGRectContainsPoint(self.button.bounds, newPoint)) {
                view = self.button;
            }
        }
        return view;
    }
    
    -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    
    {
    
        UIView *view = [super hitTest:point withEvent:event];
    
        
    
        if (view == nil) {
    
            for (UIView *subView in self.subviews) {
    
                CGPoint myPoint = [subView convertPoint:point fromView:self];
    
                if (CGRectContainsPoint(subView.bounds, myPoint)) {
    
                    
    
                    return subView;
    
                }
    
            }
    
        }
    
        
    
        return view;
    
    }
    

    相关文章

      网友评论

          本文标题:button超出父视图无法点击解决

          本文链接:https://www.haomeiwen.com/subject/wjntdctx.html