Ios UILongPressGestureRecognitor将触摸传递到UIWebView

Ios UILongPressGestureRecognitor将触摸传递到UIWebView,ios,objective-c,uiwebview,uigesturerecognizer,Ios,Objective C,Uiwebview,Uigesturerecognizer,我将ui长按手势识别器添加到ui网络视图: UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouch:)]; longPress.delegate = self; longPress.minimumPressDuration = 0.5; longPress.cancelsTouchesInView =

我将
ui长按手势识别器
添加到
ui网络视图

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouch:)];
longPress.delegate = self;
longPress.minimumPressDuration = 0.5;
longPress.cancelsTouchesInView = YES;

[_webView addGestureRecognizer:longPress];
cancelsTouchesInView
设置为
YES
,但长按超链接后,触摸传递到
UIWebView
UIWebView
单击此超链接并加载其他页面


长按后如何禁用对
UIWebView
的触摸?

您可以使用下面的代码来阻止webview内容内部的触摸链接-

@property (assign, nonatomic) BOOL allowLoad;

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    return allowLoad;
}

- (void)webViewDidFinishLoad:(UIWebView*)webView {
    allowLoad = NO;
}
不要忘记设置委托
[self.webView setDelegate:self]


希望这将帮助您

实现以下手势代理方法,以防止长按时触碰web视图:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isDescendantOfView:self.webView])
    {
        //Ignore gesture when it's web view
        return NO;
    }

    return YES;
}
更新

请尝试以下代码-

-(void)webViewDidFinishLoad:(UIWebView *)webView 
{
    [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];   
} 

此代码禁止所有对超链接的单击。但我不需要禁止他们。仅当长按时,我需要禁用对UIWebView的传递触摸。此代码无效。长时间按下后,仍然会单击UIWebView中的超链接。我的项目中已经有了这个javascript代码,但它并没有解决我所描述的问题。