2010-09-17 52 views
0

我在webview中顯示一個pub或一個pdf文件。但我無法檢測到在web視圖上的觸摸。如何在webview被連續觸摸10秒後顯示一個視圖?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

上述方法,當我接觸到PDF或酒吧file.How的任何文字,我可以檢測其上顯示的PDF或酒吧file.Please幫我out.Thanks web視圖點擊被調用。

編輯:

這是我的代碼:

- (void)viewDidLoad { 
[super viewDidLoad]; 
NSURL *url = [NSURL URLWithString:@"http://dblog.com.au"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:request]; 
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
longPressGestureRecognizer.minimumPressDuration = 6.0; 
[self.webView addGestureRecognizer:longPressGestureRecognizer]; 
[longPressGestureRecognizer release]; 

} 

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer { 
NSLog(@"Long press detected"); 
} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
return YES; 
} 

請檢查一下,我有沒有犯任何錯誤?

+0

看起來好吧,你必須添加 youre.h,並設置longPressGestureRecognizer.delegate = self .. – LarsJK 2010-09-17 11:50:12

回答

4

嘗試類似:

UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
longPressGestureRecognizer.minimumPressDuration = 10.0; 
[self.webView addGestureRecognizer:longPressGestureRecognizer]; 
[longPressGestureRecognizer release]; 

然後:

- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer { 
    NSLog(@"Long press detected"); 
} 

編輯:

補充一點:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
return YES; 
} 

但按同一地點10秒是一個真的很長時間... defa長按的最大值爲0.4秒。請記住,如果手指被拖動,它不再是一個長按..

+0

@Larsaronen:對不起不工作.... – Warrior 2010-09-17 10:16:41

+0

嘗試在我編輯的文章中添加新的方法! – LarsJK 2010-09-17 10:57:00

+0

@Larsaronen:我編輯了我的問題併發布了我的代碼。請仔細閱讀它... – Warrior 2010-09-17 11:20:50

相關問題