iOS 11.2自定义导航栏无限循环



自从iOS 11.2发布时,我的应用在推动导航控制器具有自定义导航栏高度的视图控制器时遇到了无限环路。有人找到了解决这个问题的解决方案吗?谢谢。

-(void)layoutSubviews{
   [super layoutSubviews];
   float height = 42.5;
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
       height = 48;
   }
   imageView.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, height);
   if(UI_USER_INTERFACE_IDIOM() ==UIUserInterfaceIdiomPad){
       if(@available(iOS 11.0,*)){
           self.frame =CGRectMake(0, 20,[[UIScreen mainScreen]bounds].size.width, 55); // this line provoke the infinite loop
           for(UIView *aView in self.subviews){
               if([NSStringFromClass([aView class]) isEqualToString: @"_UINavigationBarContentView"]){
                   aView.frame = CGRectMake(0, 10, aView.frame.size.width, aView.frame.size.height);
               }
               if([NSStringFromClass([aView class]) isEqualToString: @"_UIBarBackground"]){
                   aView.frame = CGRectMake(0, 0, aView.frame.size.width, self.frame.size.height );
               }
           }
       }
   }
}

我也有同样的问题。
我通过删除此

解决了
frame.size.height = customHeight

来自layoutsubviews,然后添加此

override var frame: CGRect {
    get {
        return CGRect(x: 0, y: 0, width: super.frame.width, height: customHeight)
    }
    set (value) {
        super.frame = value
    }
}

到我的uinavigationbar子类。
我像以前一样将所有其他代码留在layoutsubviews中。(NB)

最新更新