iOS 11 UIWebView状态栏下拉
iOS 11 UIWebView pop down by status bar
在iOS11中,UIWebView被状态栏弹出。它可能受到 iOS 11 引入的安全区域插入的影响。我尝试将 属性 contentInsetAdjustmentBehavior 设置如下:
webView.scrollowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways
有效。但是,对于某些使用-webkit-overflow-scrolling 的页面,webView.scrollowView 有另一个 UIScrollowView(UIWebOverflowScrollView) 作为它的子视图。如果我不为该 scrollView 设置 属性 contentInsetAdjustmentBehavior,页面元素将下沉。如果没有为 UIWebview 的所有滚动视图设置 属性 contentInsetAdjustmentBehavior 的任何其他解决方案。
我遇到了类似的问题。我正在设置我的 UICollectionView contentInset pre iOS 11.
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);
}
实际上,我创建了一个隐藏导航栏但未隐藏状态栏的全屏 webView。
对于WKWebView,Apple从iOS 11 beta 8开始修复了https://github.com/WebKit/webkit/commit/cb45630904c7655cc3fb41cbf89db9badd1ef601这里的bug,所以我们可以设置[=24=的属性 contentInsetAdjustmentBehavior ]:
wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
对于UIWebView(Apple已经放弃UIWebView),我们可以通过设置rootViewController的属性 additionalSafeAreaInsets来调整UIViewController的safearea(是的,只有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);
如果您想完全在 HTML 和 CSS 中处理这个问题,这是可能的。
首先,您需要将 viewport-fit=cover
添加到视口元标记中,以便 WebView 在状态栏后面填满整个屏幕 space。
接下来,为确保您安全地处理 iPhone X 及其缺口 speaker/camera 区域,您需要设置填充以使用新的 CSS 顶部和底部的安全区域插入常量:
即,padding-top: constant(safe-area-inset-top);
我写了一些关于视口的这些变化和新功能,如 CSS 添加常量以支持它们:https://ayogo.com/blog/ios11-viewport/
在iOS11中,UIWebView被状态栏弹出。它可能受到 iOS 11 引入的安全区域插入的影响。我尝试将 属性 contentInsetAdjustmentBehavior 设置如下:
webView.scrollowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways
有效。但是,对于某些使用-webkit-overflow-scrolling 的页面,webView.scrollowView 有另一个 UIScrollowView(UIWebOverflowScrollView) 作为它的子视图。如果我不为该 scrollView 设置 属性 contentInsetAdjustmentBehavior,页面元素将下沉。如果没有为 UIWebview 的所有滚动视图设置 属性 contentInsetAdjustmentBehavior 的任何其他解决方案。
我遇到了类似的问题。我正在设置我的 UICollectionView contentInset pre iOS 11.
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);
}
实际上,我创建了一个隐藏导航栏但未隐藏状态栏的全屏 webView。 对于WKWebView,Apple从iOS 11 beta 8开始修复了https://github.com/WebKit/webkit/commit/cb45630904c7655cc3fb41cbf89db9badd1ef601这里的bug,所以我们可以设置[=24=的属性 contentInsetAdjustmentBehavior ]:
wkWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever
对于UIWebView(Apple已经放弃UIWebView),我们可以通过设置rootViewController的属性 additionalSafeAreaInsets来调整UIViewController的safearea(是的,只有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);
如果您想完全在 HTML 和 CSS 中处理这个问题,这是可能的。
首先,您需要将 viewport-fit=cover
添加到视口元标记中,以便 WebView 在状态栏后面填满整个屏幕 space。
接下来,为确保您安全地处理 iPhone X 及其缺口 speaker/camera 区域,您需要设置填充以使用新的 CSS 顶部和底部的安全区域插入常量:
即,padding-top: constant(safe-area-inset-top);
我写了一些关于视口的这些变化和新功能,如 CSS 添加常量以支持它们:https://ayogo.com/blog/ios11-viewport/