我添加了 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
设置为 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;
}
不要忘记设置委托(delegate)
[self.webView setDelegate:self];
希望这会对你有所帮助
关于ios - UILongPressGestureRecognizer 将触摸传递给 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30591344/