在旋转时调整UINavigationBar的大小

MW.*_*MW. 7 iphone landscape rotation uinavigationbar autoresize

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

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

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

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

编辑:我在一点帮助下解决了它,阅读下面发布的答案.

Dou*_*yle 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 ...
}
Run Code Online (Sandbox Code Playgroud)


MW.*_*MW. 1

我找到了解决方案,事后看来我觉得很愚蠢。我只需在导航栏的自动调整大小蒙版中包含灵活的底部边距。感谢此线程中的用户 RayNewbie,它向我指出了解决方案:

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