【问题标题】:Subview outside of main view does not receive touch events主视图外的子视图不接收触摸事件
【发布时间】:2012-06-19 14:51:44
【问题描述】:

在我的应用程序中,我有一个主屏幕,它有一个子视图(这是另一个屏幕),但是这个子视图向右移动了 320,所以它只是在屏幕外。效果是主屏幕向左移动了320,隐藏了主屏幕并显示了另一个屏幕,因为它是一个子视图。问题是,另一个屏幕没有接收到触摸事件,因为它超出了主屏幕(superview)的范围。如何让另一个屏幕也接收触摸事件,以便我可以点击按钮?

【问题讨论】:

    标签: iphone objective-c uiview


    【解决方案1】:

    查看this post on S.O. 以获得解释。解决方案是使用以下代码实现自己的 hitTest:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    
        BOOL isInside = [super pointInside:point withEvent:event];
    
        // identify the button view subclass
        UIButton *b = (UIButton *)[self viewWithTag:3232];
        CGPoint inButtonSpace = [self convertPoint:point toView:b];
    
        BOOL isInsideButton = [b pointInside:inButtonSpace withEvent:nil];
    
        if (YES == isInsideButton) {
    
           return isInsideButton;
    
        } // if (YES == isInsideButton)
    
        return isInside;
     }
    
     - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
        UIView *v = nil;
    
        v = [super hitTest:point withEvent:event];
    
        return v;
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 2018-02-27
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      相关资源
      最近更新 更多