WKWebView遇到的问题汇总


一.手势放大缩小页面解决方法

1.通过操作webview中scrollview的代理方法来关闭

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return nil;
}

但是中途出现了一个问题就是在网页适配iPhone X的时候添加的js适配代码导致失效问题

2.通过注入js来关闭手势捏合效果

_webConfig = [WKWebViewConfiguration new];
WKUserContentController *userController = [WKUserContentController new];
NSString *js = @" $('meta[name=description]').remove(); $('head').append( '<meta name=\"viewport\" content=\"width=device-width, initial-scale=1,user-scalable=no\">' );";
WKUserScript *script = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
[userController addUserScript:script];
[userController addScriptMessageHandler:self name:@"openInfo"];
_webConfig.userContentController = userController;

但是这种方法没有起作用,可能是被覆盖了,于是用的上面的方法

 

二.关闭WKWebview中长安手势触发3d touch的效果

已开始上网搜说js可以自己关闭,确实是关闭了,但是整个页面不能滑动了,所以还是自己关闭通过下面的代码

for (UIView* subview in self.wkWebView.scrollView.subviews) {
        if ([subview isKindOfClass:NSClassFromString(@"WKContentView")]) {
            for (UIGestureRecognizer* longPress in subview.gestureRecognizers) {
                if ([longPress isKindOfClass:UILongPressGestureRecognizer.class]) {
                    [subview removeGestureRecognizer:longPress];
                }
            }
        }
 }

通过取消WKContentView上所有的长按手势来关闭

 

by:初光夫


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM