在我的应用程序中,我有一个主屏幕,它有一个子视图(这是另一个屏幕),但是这个子视图向右移动320,所以它只是在屏幕外。效果是主屏幕向左移动320,其隐藏主屏幕并显示另一个屏幕,因为它是子视图。问题是,另一个屏幕没有接收到触摸事件,因为它超出了主屏幕的范围(超级视图)。如何让其他屏幕也接收触摸事件,以便点按按钮?
答案 0 :(得分:0)
请查看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;
}