我在 UIViewController 之上有一个 UIScrollView,当您在某个地点的页面上时,它会重新创建像 Gowalla iPhone 应用程序中一样的效果。在我的 ScrollView 下,我有一个按钮,即使 ScrollView 的框架覆盖了它(在按钮的顶部, ScrollView 是清晰的),我也希望能够执行它的操作。我该怎么做这样的事情?是否可以? (一定是,Gowalla [不知何故]做到了)
最佳答案
对于我来说,我会通过重写以下方法将触摸事件转移到另一个 View 。
- -touchesBegan:withEvent:
- -touchesMoved:withEvent:
- -touchesEnded:withEvent:
- -touchesCancelled:withEvent:
像这样,
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// pass touch event by default implement.
[super touchesBegan:touches withEvent:event];
// redirect the touch events.
[anotherView touchesBegain:touches withEvent:event];
}
hitTest:withEvent: 用于决定哪个 View 应该响应 View 层次树上的触摸事件。如果 View 不想响应触摸事件,则会在 hitTest 中返回 nil。因此上述触摸事件方法将不会被调用。
关于iphone - 如何获取UIScrollView下的UIView来检测触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5366152/