iOS 导航栏隐藏现实正确方式
2018-02-09 本文已影响0人
顺其自然_Cao
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillDisappear:animated];
}
还有两个关键属性pus进去pop回来20像素高度问题。使用这两个属性。
if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
self.edgesForExtendedLayout=UIRectEdgeNone;
self.navigationController.navigationBar.translucent = NO;
}
或者直接
self.edgesForExtendedLayout=UIRectEdgeNone;
self.navigationController.navigationBar.translucent = NO;
这里还有个坑。已经解决。
iOS11的系统edgesForExtendedLayout方法弃用。使用下面的可以完美解决。亲测iOS10和11的系统都没多那20像素。
if (@available(iOS 11.0, *)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
//self.edgesForExtendedLayout = UIRectEdgeNone;
// Fallback on earlier versions
}