问题描述
所以我有以下层次结构:
So I have the following hierarchy:
UINavigationController
--> RootViewController (UIViewController
) --> UITableViewController
--> DetailViewController (UIViewController
)
UINavigationController
--> RootViewController (UIViewController
) --> UITableViewController
--> DetailViewController (UIViewController
)
我想将 RootViewController 上的方向锁定为仅纵向,但保留其余视图控制器的所有方向.
I want to lock the orientation on RootViewController to Portrait only, but leave all orientations for the rest view controllers.
如果我把它放到子类 UINavigationController
:
If I put this to subclassed UINavigationController
:
然后所有视图控制器都被锁定为纵向.
All view controllers are then locked to portrait.
我的问题是,有没有办法只将 RootViewController 锁定为 Portrait,而将所有选项留给其他视图控制器?
My question is, is there a way to lock only RootViewController to Portrait, but leave all options for other view controllers?
推荐答案
查看此处的链接以修复 iOS 6 中的自动旋转并根据视图设置方向支持:http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/
check the link here for fixing autorotation in iOS 6 and set orientation support per view basis: http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/
你可以这样做:
在您的 .m 文件中创建一个自定义导航控制器,它是
UINavigationController
的子类:
在你的 AppDelegate.h
,
在AppDelegate.m
中,
在您的 rootViewController 中,无论事件推送第二个视图控制器,请执行以下操作:
in your rootViewController, for whatever the event push the second view controller, do this:
在每个视图控制器中,添加
in your each view controller, add
对于 iOS 6,您可以单独设置每个视图控制器所需的方向支持.
for iOS 6, you can set each view controller whatever the orientation support you want individually.
对于iOS 5及以下,可以设置
for iOS 5 and below, you can set
所有功劳归于在链接中编写示例应用的 John DiSalvo.
All the credits goes to John DiSalvo who wrote the sample app in the link.
希望这会有所帮助.
这篇关于UINavigationController 中的 ViewController 方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!