问题
近期有个需求,需要在WKWebView加载PDF中,基于安全的理由,屏蔽【复制、选择全部】等功能弹窗
解决方案
捕捉长按手势后进行屏蔽,问题是,原来手势是放在view的subview中,导致一直屏蔽view的长按手势没法生效
// 页面加载完成之后调用 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ DebugLog(@"WKWebViewFinishNavigation"); // 禁用长按效果 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ for (UIView *view in webView.subviews) { for (UIView * subview in view.subviews) { for (UIGestureRecognizer *gesture in subview.gestureRecognizers) { if ([NSStringFromClass([gesture class]) isEqualToString:@"UILongPressGestureRecognizer"] ) { [subview removeGestureRecognizer:gesture]; } } // if ([NSStringFromClass([subview class]) isEqualToString:@"_UISizeTrackingView"]) { // NSLog(@"gestureRecognizers:%@",subview.gestureRecognizers); // // } } } }); }