- 导航栏的titleView需要自定义View,并实现
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
(注意,多层view时,底层需要放一个View承载)
2.导航栏左侧和右侧按钮不能为view,最好为button
3.导航栏下移的话使用下面的代码。。还有tableview的安全区
// automaticallyAdjustsScrollViewInsets属性被废弃了,顶部就多了一定的inset,关于安全区域适配
// 导航栏差20pt 或
if (@available(iOS 11.0, *)) {
self.baseTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
// self.baseTableView.estimatedRowHeight = 0;
// self.baseTableView.estimatedSectionHeaderHeight = 0;
// self.baseTableView.estimatedSectionFooterHeight = 0;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
4.所以如果你的项目是自定义的navigationBar,那么在iOS11上运行就可能出现布局错乱的bug,解决办法是重写UINavigationBar的layoutSubviews方法,调整布局,上代码:
-
(void)layoutSubviews {
[super layoutSubviews];//注意导航栏及状态栏高度适配
self.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), naviBarHeight);
for (UIView *view in self.subviews) {
if([NSStringFromClass([view class]) containsString:@"Background"]) {
view.frame = self.bounds;
}
else if ([NSStringFromClass([view class]) containsString:@"ContentView"]) {
CGRect frame = view.frame;
frame.origin.y = statusBarHeight;
frame.size.height = self.bounds.size.height - frame.origin.y;
view.frame = frame;
}
}
}