如何防止标签栏控制器中的视图控制器旋转? [英] How to prevent the view controllers in a tab bar controller from rotating?

查看:80
本文介绍了如何防止标签栏控制器中的视图控制器旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个管理4个标签的标签栏控制器.我将标签栏控制器细分为子类,以便shouldAutorotateToInterfaceOrientation:方法仅允许其中一个标签中的特定视图控制器旋转.一切工作正常:其余选项卡中的控制器不会旋转.但是,当允许旋转的视图控制器实际旋转时,如果用户点击剩余的选项卡之一,则相应的视图控制器也会显示为旋转(即使其shouldAutorotateToInterfaceOrientation:方法显式返回NO).

I have a tab bar controller managing 4 tabs. I have subclassed the tab bar controller so that the shouldAutorotateToInterfaceOrientation: method only allows a specific view controller in one of the tabs to rotate. Everything works almost fine: the controllers in the remaining tabs do not rotate. However, when the view controller which is allowed to rotate actually rotates, if the user taps one of the remaining tabs, the corresponding view controller also appear rotated (even though its shouldAutorotateToInterfaceOrientation: method explicitly returns NO).

如何防止这种情况发生?

How do I prevent this from happening?

为清楚起见,这是一个示例.轻触选项卡0,1或2并尝试旋转设备,则没有任何反应(正确).轻触选项卡4并旋转设备,与选项卡4的视图控制器关联的视图将旋转(正确).现在,仍然将iPhone保持在旋转的横向方向上,然后点击另一个选项卡(0、1或2)将显示旋转的视图(这是不正确的,也是我想避免的事情).

To be clear, here is an example. Tapping on the tabs 0,1, or 2 and trying to rotate the device, nothing happens (correctly). Tapping on the tab 4 and rotating the device, the view associated to the view controller of tab 4 is rotated (correctly). Now, still holding the iPhone in the rotated landscape orientation and tapping another tab (0,1, or 2) reveal a rotated view (which is not correct and what I am trying to avoid).

推荐答案

这是一个经常报告的错误"-但是,一个好的解决方法是强制按以下方式触发shouldAutorotateToInterfaceOrientation:选择器:

This is a commonly reported "bug" - however a good workaround is to force the shouldAutorotateToInterfaceOrientation: selector to be triggered as follows:

- (void)viewDidAppear:(BOOL)animated {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *view = [window.subviews objectAtIndex:0];
    [view removeFromSuperview];
    [window addSubview:view];
}

这篇关于如何防止标签栏控制器中的视图控制器旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆