1 问题发现: ios app下 内容可以上下滑动 内容不固定 (webview页面遮挡状态栏或者距离太近 显示不友好)
解决问题:
ios 11 新增 :meta 标签中 添加 viewport-fit=cover,这是 ios 11 新增的设置,可以让页面全屏展示。
<meta name="viewport" content="initial-scale=1, width=device-width, height=device-height, maximum-scale=1, minimum-scale=1, user-scalable=no, viewport-fit=cover">
然后 控制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];
}
以下是代码:
- (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];
}
在MainViewConController.m中 增加
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
解决完毕
也可以借鉴以下文章