最近苹果正式推送了iOS 11.0 ,更新了xcode和系统后导航栏遇到了问题。
iOS 11.0因为新增largeTitle功能的缘故,结构层次有所改变。(本文没有对largeTitle和ipX适配,请主意)
Talk is cheap. Show you the code。
-(void)layoutSubviews
{
[super layoutSubviews];
/**
fix iOS 11.0 导航栏上移20px
*/
// if (self.frame.origin.y != 0) {
// CGRect rc = self.frame;
// rc.origin.y = 0;
// self.frame = rc;
// }
for (UIView *subView in self.subviews) {
if ([NSStringFromClass([subView class]) isEqualToString: @"_UIBarBackground"]) {
CGRect rc = subView.frame;
rc.size.height = 64.f;
rc.origin.y = 0.f;
subView.frame = rc;
}else if ([NSStringFromClass([subView class]) isEqualToString: @"_UINavigationBarContentView"]){
CGRect rc = subView.frame;
rc.size.height = 44.f;
rc.origin.y = 20.f;
subView.frame = rc;
}
}
}