PDF文件使用WKWebView展示的时候使用以下方法并不能禁用长按手势
[self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
[self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
需要找到pdf展示出来的时候删除掉加载在WKScrollView上的长按手势,即使WKWebView触发了didFinishNavigation代理方法,也不能立马获取到PDF的长按手势,因为PDF加载需要时间,这里延时0.3s可以获取到长按手势,然后禁用就行
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
// 禁用长按效果
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (UIView *view in self.webView.subviews) {
if ([NSStringFromClass([view class]) isEqualToString:@"WKScrollView"]) {
for (UIGestureRecognizer *gesture in view.gestureRecognizers) {
if ([NSStringFromClass([gesture class]) isEqualToString:@"UILongPressGestureRecognizer"]) {
[view removeGestureRecognizer:gesture];
}
}
}
}
});
}
网友评论