【问题标题】:touchesBegan not responding触摸开始没有响应
【发布时间】:2011-03-19 10:23:15
【问题描述】:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@" 触摸"); }

上述方法没有在我的应用程序中调用。我的申请说明如下。

我有一个MainViewController,它在其中加载了一个ContentViewControllerContentViewController 有一个加载 pdf 文件的 webview。

如何听MainViewController's View的点击。

问候。

【问题讨论】:

标签: objective-c


【解决方案1】:

我在这里可能不是 100% 准确,但是如果您将 -touchesBegan:withEvent: 放置在您的视图控制器(或其主视图)中,那么您将仅获得视图层次结构中某些子视图未处理的那些触摸。要拦截所有触摸,您应该为控制器视图使用 UIView 子类并覆盖其中的 hitTest:withEvent: 方法:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    touchedView = [super hitTest:point withEvent:event];
    NSSet* touches = [event allTouches];
    // handle touches if you need
    return touchedView;
}

有关更多信息,请参阅 iOS 的“事件处理指南”中的 Event delivery 部分

【讨论】:

  • 更新了答案,其中包含 Apple 文档中事件处理说明的链接 - 它似乎证实了我的答案
  • 我这样做了。它的工作。但是现在 UIWebView 已经停止工作了。
  • 什么不完全有效?您是否从 hitTest 方法返回正确的视图?
猜你喜欢
  • 2013-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-13
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多