Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 触摸开始没有反应_Objective C - Fatal编程技术网

Objective c 触摸开始没有反应

Objective c 触摸开始没有反应,objective-c,Objective C,-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件 { NSLog(@“触摸”); } 上述方法未在我的应用程序中调用。我的申请说明如下 我有一个MainViewController,它在其中加载一个ContentViewControllerContentViewController有一个加载pdf文件的webview 如何收听mainview控制器的视图的点击 注意。我在这里可能不是100%准确,但如果您将-touchesbeated:withEvent:放置在视图控制器(

-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件 { NSLog(@“触摸”); }

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

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

如何收听
mainview控制器的
视图的点击


注意。

我在这里可能不是100%准确,但如果您将
-touchesbeated: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“事件处理指南”中的部分

更新的答案,以及Apple文档中的事件处理解释链接-它似乎证实了我的回答,我做到了这一点。它起作用了。但是现在UIWebView已经停止工作了。到底什么不起作用?您是否从hitTest方法返回正确的视图?请查看链接:此答案非常有用: