iphone - 如何获取UIScrollView下的UIView来检测触摸?

标签 iphone uiscrollview touches

我在 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/

相关文章:

iphone - Array addObject 正在更改所有数组值,而不仅仅是附加

ios - 由于弹跳而无法获得正确的 ScrollView 方向

swift - 隐藏节点不显示带有名称的子节点

iphone - CIFaceFeature 仅适用于 LandscapeLeft

iphone - 使用 CAKeyframeAnimation 和路径时出现间歇性 fillMode=kCAFillModeForwards 错误

iphone - 通过 Objective-C 创建 SQLite3 数据库文件

iOS 11 TableView 到导航栏下方的 UIView 奇数空间

ios - UIScrollViews subview 没有在纵向到横向方向更改上调整自己的大小

uiimageview - IOS。如何启用透明图像将触摸传递到其下方的 UIButton?

ios - 第一次触摸后触摸次数显示为1