【问题标题】:WKWebView pinch-to-zoom in iOS10iOS10中的WKWebView捏拉缩放
【发布时间】:2016-08-05 05:10:23
【问题描述】:

我的手机升级到iOS 10 beta 3后遇到一个问题,当我在我的应用中缩放一个WKWebView时,缩放功能不仅会缩放网页的内容,还会缩放页面本身。

请看我附上的图片。 WKWebView that fails to zoom correctly.我将WKWebView的背景色设置为蓝色,当我捏缩小视图时,页面(容器?)本身也缩小了,导致不利的结果。 在 iOS9 中不会发生。 当我做同样的事情时,蓝色背景不显示。 该网页是用AngularJS 编写的,Graph libd3js

相关代码如下。

-(void) reloadWebPage{
    [activityIndicator startAnimating];
    NSString *indexToPath = [self getIndexHtmlPath];
    NSURL *fileUrl = [NSURL fileURLWithPath:indexToPath];
    NSURL *absoluteUrl = fileUrl.absoluteURL;
    if(currentGroup == nil){
        currentGroup = @"0";
    }
    NSString *absoluteString = [[absoluteUrl absoluteString] stringByAppendingFormat:@"%@%@", @"?currentGroup=", currentGroup];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:absoluteString] ];
    [webView loadRequest:request];

}

- (void)createWebView{

    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    [config.userContentController addScriptMessageHandler:self name:@"interOp"];
    webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:config];
    [webView setBackgroundColor:[UIColor blueColor]];
    [webView setNavigationDelegate:self];
    [webView setUIDelegate:self];
}

我不知道问题出在哪里?它是在 Objective C、iOS10 中还是在 Javascript 中?
请建议,我该如何解决这个问题?

谢谢

【问题讨论】:

  • 您提到的链接旨在禁用缩放,我不想禁用它。另外我也没用user-scalable=no
  • 好的,我知道了。可以给个问题页面的链接吗?
  • 是的,我做到了。请参阅链接“无法正确缩放的 WKWebView”。在问题中。

标签: ios objective-c webview ios10


【解决方案1】:

好的,我通过在WKWebView 中禁用缩放和滚动解决了这个问题。

webView.scrollView.scrollEnabled = false;

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

添加这些代码后,WKWebView 本身不再缩放和移动,而节点正常移动和缩放。

这个问题似乎和Disable magnification gesture in WKWebView有些关系,但是 我仍然不知道是什么导致了从 iOS9 到 iOS10 的变化。但它似乎对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-31
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2012-11-24
    • 2012-03-20
    • 2012-11-23
    相关资源
    最近更新 更多