2012-07-30 214 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;