在使用WKWebView展示页面时,通常希望全屏展示,但是界面上方与预留状态栏的高度,这就不是理想的全屏效果。
有两种思路
一种是APP不显示状态栏
另外就是修改WKWebView的显示属性(iOS 11开始支持)
//设置监听
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
[userContentController addScriptMessageHandler:self name:@"app”];
// 设置偏好设置
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
config.userContentController = userContentController;
//解决音乐播放问题
config.allowsInlineMediaPlayback = YES;
config.mediaPlaybackRequiresUserAction = false;
//解决状态栏空白问题
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT ) configuration:config];
if (@available(iOS 11.0, *)) {
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
_webView.scrollView.bounces = YES;
_webView.navigationDelegate = self;
_webView.scrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:_webView];
NSString* urlString;
//页面加载逻辑
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@“https://www.baidu.com”]]];
网友评论