[英]UILongPressGestureRecognizer pass touches to UIWebView
I added UILongPressGestureRecognizer
to UIWebView
: 我将
UILongPressGestureRecognizer
添加到UIWebView
:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouch:)];
longPress.delegate = self;
longPress.minimumPressDuration = 0.5;
longPress.cancelsTouchesInView = YES;
[_webView addGestureRecognizer:longPress];
cancelsTouchesInView
set to YES
, but after long press on hyperlink touch pass to UIWebView
and UIWebView
click on this hyperlink and load other page. cancelsTouchesInView
设置为YES
,但是长按超链接后,将触摸传递给UIWebView
和UIWebView
然后单击此超链接并加载其他页面。
How can I disable touches to UIWebView
after long press? 长按后如何禁用对
UIWebView
触摸?
You may used below code to prevent touch links inside of webview content - 您可能会使用以下代码来阻止Webview内容内的触摸链接-
@property (assign, nonatomic) BOOL allowLoad;
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
return allowLoad;
}
- (void)webViewDidFinishLoad:(UIWebView*)webView {
allowLoad = NO;
}
Don't forgot to set delegate [self.webView setDelegate:self];
不要忘记设置委托
[self.webView setDelegate:self];
Hope this will be help you 希望这会对您有所帮助
Implement below gesture delegate method to prevent web view touch on long press: 实现以下手势委托方法,以防止长时间按下网页视图:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isDescendantOfView:self.webView])
{
//Ignore gesture when it's web view
return NO;
}
return YES;
}
Update 更新
Please try with below code - 请尝试以下代码-
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.