iOS 6:将视图控制器推入导航控制器堆栈时如何强制更改方向 [英] iOS 6: how to force change orientation when pushing view controller into the navigation controller stack
问题描述
我认为这个问题现在应该被问过一百万次,但我仍然无法找到答案。
I think this question should've been asked a million times by now, but I still can't find an answer to this.
这是我的层次结构:UINavigationController - > UIViewController 1 - >(push) - > UIViewController 2
Here's my hierarchy: UINavigationController -> UIViewController 1 ->(push)-> UIViewController 2
UINavigationController:支持所有可能的方向
UIViewController 1:仅支持portrait
UIViewController 2 :仅支持横向
UINavigationController: supports all possible orientation UIViewController 1: supports only portrait UIViewController 2: supports only landscape
如何仅将UIViewController 1锁定为纵向,同时仅将UIViewController 2锁定为横向?它甚至可能吗?到目前为止,我看到的是UIViewController 2始终采用UIViewController 1的方向。
How can I lock UIViewController 1 into portrait only and at the same time lock UIViewController 2 into landscape only? Is it even possible? So far what I see is that UIViewController 2 always takes the orientation of UIViewController 1.
注意,这仅适用于iOS 6。
Note, that this is for iOS 6 only.
谢谢!
推荐答案
我也发现同样的问题。我发现shouldAutorotate函数没有调用每次所以我改变方向程序
I am also find the same problem.i have found that shouldAutorotate function not call every time so i change orientation programmatic
首先导入此
#import <objc/message.h>
然后
-(void)viewDidAppear:(BOOL)animated
{
if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );
}
}
}
希望这对你有帮助。
这篇关于iOS 6:将视图控制器推入导航控制器堆栈时如何强制更改方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!