导航栏的横向模式问题

时间:2010-11-18 19:47:52

标签: ios uinavigationbar landscape

我有一个ViewController来管理一个视图,其中我有一个Table View,一个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;
}

但没有。 我该如何解决这个问题?

2 个答案:

答案 0 :(得分:8)

我犯了一个错误,没有一个navigationController,所以我将IB中的导航栏与代码中的插座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;  
}

现在可以使用了,我的图片视图只有一个问题

答案 1 :(得分:0)

导航顶部栏的自定义背景图像存在同样的问题。

我的风景图像不是正确的高度,它是44px高而不是32px(对于@ 2x版本来说相同,它是88px而不是64px)。裁剪图像后,横向顶栏的高度正确。

相关问题