2012-07-30 100 views

回答

4

這裏是實現單輕叩和雙擊上的WebView

UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)] autorelease]; 
singleTap.numberOfTapsRequired = 1; 
[self.myWebView addGestureRecognizer:singleTap]; 


UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doDoubleTap)] autorelease]; 
doubleTap.numberOfTapsRequired = 2; 
[self.myWebView addGestureRecognizer:doubleTap]; 
+0

如何才能辨別用戶點擊單個或兩次。有代表嗎? – Codesen 2012-07-30 09:52:55

0

將下面的代碼3個環節就能解決你的問題

how-to-add-a-gesture-recognizer-to-a-uiwebview-subclass

iphone-custom-gestures-on-your-uiwebview

does-uigesturerecognizer-work-on-a-uiwebview

關於抽頭數,你可以將它通過屬性numberOfTapsRequired

如:

UITapGestureRecognizer *myGusture = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doTap)] autorelease]; 
myGusture.numberOfTapsRequired = 1; //you can change it to any number as per your requirement. 
[self.myWebView addGestureRecognizer:myGusture]; 
[myGusture release]; 
myGusture = nil;