iOS 11.2 custom navigation bar infinite loop

546 Views Asked by At

Since the release of IOS 11.2 my app is encountering an infinite loop when pushing a view controller whose navigation controller has a custom navigation bar height. Did someone find the solution for this problem? Thanks.

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

           }

       }
   }
}
1

There are 1 best solutions below

1
On

I also had the same problem.
I solved by removing this

frame.size.height = customHeight

from layoutSubviews and then adding this

override var frame: CGRect {

    get {

        return CGRect(x: 0, y: 0, width: super.frame.width, height: customHeight)

    }
    set (value) {
        super.frame = value

    }

}

to my UINavigationBar subclass.
I left all other code in layoutSubviews as it was before. (nb)