在旋转时调整UINavigationBar的大小

时间:2009-12-01 12:52:29

标签: iphone rotation uinavigationbar landscape autoresize

我有一个UIViewController的子类来处理UIView。视图控制器以模态方式呈现(它从屏幕底部向上滑动)。在视图的顶部,我添加了一个导航栏。请注意,此栏不由导航控制器处理。

当视图旋转到横向时,我希望导航栏的高度会缩小(类似于UINavigationController处理时的行为方式)。但是,我无法在IB中将其自动调整遮罩设置为灵活高度,并且在代码中这样做会导致导航栏完全消失。

有办法做到这一点吗?它是如何通过UINavigationController完成的?

P.S。我宁愿不必采用缩放变换,因为这会弄乱标题中的文本。

编辑:我在一点帮助下解决了这个问题,请阅读下面的答案。

2 个答案:

答案 0 :(得分:5)

为什么不在viewWillAppear和didRotateFromInterfaceOrientation中检查当前方向,并设置相应的框架,而不是设置它的自动调整遮罩?

- (void) updateNavBar {
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if ((UIInterfaceOrientationLandscapeLeft == orientation) ||
        (UIInterfaceOrientationLandscapeRight == orientation)) {
        myNavBar.frame = CGRectMake(0, 0, 480, 34);
    } else {
        myNavBar.frame = CGRectMake(0, 0, 320, 44);
    }
}
- (void) viewWillAppear {
    [self updateNavBar];
    // ... SNIP ...
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [self updateNavBar];
    // ... SNIP ...
}

答案 1 :(得分:1)

我找到了解决方案,事后我感到相当愚蠢。我只需要在导航栏的autoresize掩码中包含灵活的底部边距。信用是由于用户RayNewbie在这个帖子中,它指出了解决方案:

http://discussions.apple.com/thread.jspa?messageID=8295525

相关问题