【发布时间】:2012-07-27 23:06:35
【问题描述】:
如何在 UIWebview 中识别用户 touch、tap 和 double tap。是否有任何可用的委托,例如触摸开始等?
【问题讨论】:
标签: iphone objective-c ios ipad uiwebview
如何在 UIWebview 中识别用户 touch、tap 和 double tap。是否有任何可用的委托,例如触摸开始等?
【问题讨论】:
标签: iphone objective-c ios ipad uiwebview
这里是实现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];
【讨论】:
以下 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;
【讨论】: