0

自 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 );
               }

           }

       }
   }
}
4

1 回答 1

1

我也有同样的问题。
我通过删除这个解决了

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 中。(注)

于 2017-12-21T15:14:36.840 回答