导航栏的横向模式问题

Sef*_*an2 9 landscape uinavigationbar ios

我有一个ViewController管理一个视图,其中我有一个表视图,一个ImageView和一个导航栏.当我把它放在横向模式时导航栏没有调整到32,它仍然保持到44我首先尝试在IB中使用自动调整但没有成功,然后我尝试将此代码放在ViewController中

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    //[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navigationController.navigationBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
         frame.size.height = 44;
    } else {
         frame.size.height = 32;
    }
    self.navigationController.navigationBar.frame = frame;
}
Run Code Online (Sandbox Code Playgroud)

但没什么.我该如何解决这个问题?

Sef*_*an2 8

我犯了一个错误,没有一个navigationController,所以我将IB中的导航栏与代码中的outlet navBar链接起来,我用过

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation  duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        frame.size.height = 44;
    } else {
        frame.size.height = 32;
    }
    self.navBar.frame = frame;  
}
Run Code Online (Sandbox Code Playgroud)

它现在有效,我只对图像视图有问题

  • 你需要在这个方法中调用super,它不应该被注释掉. (4认同)