iOS 11 解决UINavigationBar位置偏移

2017-09-25  本文已影响0人  NetSpeeds

最近苹果正式推送了iOS 11.0 ,更新了xcode和系统后导航栏遇到了问题。


向上偏移了20px

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;
       }
   }
}
上一篇下一篇

猜你喜欢

热点阅读