更新于:2019-02-13
关闭WKWebview中长按手势触发3d touch的效果
for (UIView* subview in self.webView.scrollView.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"WKContentView")]) {
for (UIGestureRecognizer* longPress in subview.gestureRecognizers) {
if ([longPress isKindOfClass:UILongPressGestureRecognizer.class]) {
[subview removeGestureRecognizer:longPress];
}
}
}
}
参考:https://www.cnblogs.com/widgetbox/p/9242533.html
如果想再加个长按手势,最好是加在wkwebview的scrollview上
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handlelongPressed:)];
longPress.minimumPressDuration = 1;
longPress.delegate = self;//这里的代理,主要是解决手势冲突
[self.webView.scrollView addGestureRecognizer:longPress];
解决手势冲突
#pragma mark UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer{
if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [NSStringFromClass([otherGestureRecognizer class])isEqualToString:@"UITextTapRecognizer"]){
return NO;
}
return YES;
}