解决webview页面遮挡状态栏

场景如下:


image.png

解决方案:控制webview的frame,顶部添加20的view

代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    UIView *statusBarView = [[UIView alloc]   initWithFrame:CGRectMake(0, 0,    self.view.bounds.size.width, 20)];
    statusBarView.backgroundColor = [HTMISettingManager manager].navigationBarColor;
    [self.view addSubview:statusBarView];
}
- (void)viewWillAppear:(BOOL)animated
{
     CGRect viewBounds = [self.webView bounds];
     viewBounds.origin.y = 20;
     viewBounds.size.height = viewBounds.size.height - 20;
     self.webView.frame = viewBounds;
    [super viewWillAppear:animated];
}

你可能感兴趣的:(解决webview页面遮挡状态栏)