直接上代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if (@available(iOS 11.0,*)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}else{
self.automaticallyAdjustsScrollViewInsets = NO;
}
// 同时也要设置tableView的顶部约束
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
if (@available(iOS 11.0,*) {
make.top.equalTo(self.view.mas_top);
make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
} else {
make.edges.equalTo(self.view);
}
}];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// 导航栏透明
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
// self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
// 导航栏不透明
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
// self.navigationController.navigationBar.shadowImage = nil;
}
效果如图

网友评论