【问题标题】:iOS 11 UIWebView pop down by status bariOS 11 UIWebView 由状态栏弹出
【发布时间】:2018-03-21 22:51:20
【问题描述】:

在 iOS 11 中,UIWebView 通过状态栏弹出。可能会受到 iOS 11 引入的安全区域插入的影响。我尝试将属性 contentInsetAdjustmentBehavior 设置如下:

webView.scrollowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways

它有效。但是,对于某些使用 -webkit-overflow-scrolling 的页面,webView.scrollowView 有另一个 UIScrollowView(UIWebOverflowScrollView) 作为其子视图。如果我没有为该滚动视图设置属性 contentInsetAdjustmentBehavior,页面元素将下沉。如果没有为 UIWebview 的所有 scrollView 设置属性 contentInsetAdjustmentBehavior 来解决此问题的任何其他解决方案。

【问题讨论】:

    标签: uiscrollview uiwebview uistatusbar ios11


    【解决方案1】:

    实际上,我创建了一个隐藏导航栏但未隐藏状态栏的全屏 webView。 对于 WKWebView,Apple 从 iOS 11 beta 8 开始修复了这里的 bug https://github.com/WebKit/webkit/commit/cb45630904c7655cc3fb41cbf89db9badd1ef601,所以我们可以设置 wkWebView.scrollview 的 contentInsetAdjustmentBehavior 属性:

    wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
    

    对于UIWebView(Apple已经放弃了UIWebView),我们可以通过设置rootViewController的additionalSafeAreaInsets属性来调整UIViewController的安全区域(是的,只有rootViewController的additionalSafeAreaInsets有效):

    navigationController.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
    

    或者uiWebView的框架:

    uiWebView.frame = CGRectMake(0.0, -20, uiWebView.frame.size.width, uiWebView.frame.size.height + 20);
    

    【讨论】:

      【解决方案2】:

      如果您想完全用 HTML 和 CSS 处理这个问题,这是可能的。

      首先,您需要将viewport-fit=cover 添加到视口元标记中,以便 WebView 填充状态栏后面的全屏空间。

      接下来,为确保您安全地处理 iPhone X 及其带凹槽的扬声器/摄像头区域,您需要将填充设置为在顶部和底部使用新的 CSS 安全区域插入常量之一: 即padding-top: constant(safe-area-inset-top);

      我写了更多关于视口的这些变化以及为支持它们而添加的 CSS 常量等新特性:https://ayogo.com/blog/ios11-viewport/

      【讨论】:

        【解决方案3】:

        我有类似的问题。我在 iOS 11 之前设置了我的 UICollectionView contentInset。

        CGFloat topInset = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.frame.size.height;
        CGFLoat bottomInset = self.tabBarController.tabBar.frame.size.height;     
        self.collectionView.contentInset = UIEdgeInsetsMake(topInset, 0.f, bottomInset, 0.f);
        

        我的解决方法是这样(基本上如果 iOS 11 不设置 contentInsets):

        if (![self.collectionView respondsToSelector:NSSelectorFromString(@"contentInsetAdjustmentBehavior")]) 
        {
           CGFloat topInset = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.frame.size.height;
           CGFLoat bottomInset = self.tabBarController.tabBar.frame.size.height;     
           self.collectionView.contentInset = UIEdgeInsetsMake(topInset, 0.f, bottomInset, 0.f);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-03-03
          • 1970-01-01
          • 1970-01-01
          • 2012-06-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多