Swift 探索与思考

OC WKWebView 状态栏空白,页面显示不能占满,以及播放

2018-08-21  本文已影响0人  steveMoriya

在使用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”]]];


上一篇 下一篇

猜你喜欢

热点阅读