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

问题描述 投票:0回答:1

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

           }

       }
   }
}
ios objective-c uinavigationcontroller uinavigationbar ios11.2
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中保留了之前的所有其他代码。 (NB)

© www.soinside.com 2019 - 2024. All rights reserved.