2010-07-22 103 views
2

- (void)touchesBegan:(NSSet *)touchEvent:(UIEvent *)event { NSLog(@「touches」); }touchesBegan not responding

上述方法沒有在我的應用程序中調用。我的應用程序描述如下。

我有一個MainViewController其中加載了一個ContentViewControllerContentViewController有一個加載PDF文件的webview。

如何收聽MainViewController's的點擊查看。

問候。

+0

這個答案是有幫助的:HTTP :http://stackoverflow.com/a/7808238/790198 – Nianliang 2013-11-18 11:00:40

回答

3

這裏我可能不是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; 
} 

欲瞭解更多信息,請參閱Event delivery節中的「事件處理指南」適用於iOS

+1

更新的答案與蘋果文檔中的事件處理說明鏈接 - 它似乎證實了我的答案 – Vladimir 2010-07-22 10:36:50

+0

我做到了。它的工作。但現在UIWebView已停止工作。 – TechBee 2010-07-27 09:20:39

+1

什麼不正確?你從hitTest方法返回正確的視圖嗎? – Vladimir 2010-07-27 09:27:58