UINavigationController +应该自动旋转 +没有子类化
我有一个导航驱动的应用程序。我需要那个应用程序来旋转。 UINavigationController 是窗口中的根控制器/视图。我知道(并且经历过为什么)它是 UINavigationController 子类的禁忌。我知道我所要做的就是插入:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
到 UINavigationController 中,它会很好地旋转。
所以我的问题是:如何在根视图控制器(UINavigationController)上启用旋转而不对其进行子类化?
I have a navigation driven app. I need that app to rotate. The UINavigationController is the root controller/view in the window. I know (and have experienced why) it is a no-no to subclass UINavigationController. I know all i have to do is insert:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
into the UINavigationController and it will rotate fine.
So my question is: how do I enable rotation on the root view controller (UINavigationController) WITHOUT subclassing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
rootViewController
中重写此方法,而不是在UINavigationController
中。You need to override this method in your
rootViewController
, not inUINavigationController
.你的 UINavigationController 继承自 UIViewController - 为什么使用你展示的方法是一件坏事?使用超级方法是完全合法的,并且是我在 UINavigationController 中支持旋转的唯一方法。当您从 UINavigationController 继承(并覆盖该方法以在不调用 super 方法的情况下执行其他操作时,子类化不是吗?)
Your UINavigationController inherits from UIViewController - why would using the method you show be a bad thing? It is perfectly legitimate to use a super's method and is the only way I have ever supported rotation in a UINavigationController. Wouldn't subclassing be when you inherit from UINavigationController (and override that method to do something else without calling the super method?)