[英]iPhone Interface orientation is incorrect
On iPhone - my first ViewController
supports all interface orientations. 在iPhone上-我的第一个
ViewController
支持所有界面方向。 Initial behavior though, is when I launch the app the main ViewController
should always be in portrait. 不过,最初的行为是,当我启动应用程序时,主
ViewController
应该始终处于纵向状态。
In order to overcome situations where the phone was in landscape while the app was launched, I created a dummy ViewController
which only supported portrait orientation, launched the app from it and immediately pushed the main ViewController
. 为了克服启动应用程序时手机处于横向的情况,我创建了一个仅支持纵向方向的虚拟
ViewController
,从中启动了应用程序,然后立即按下了主ViewController
。 Indeed the main ViewController
was in portrait orientation, but when performing: 实际上,主要的
ViewController
是纵向的,但是执行时:
self.interfaceOrientation
The result was landscape orientation (like the phone's orientation). 结果是横向(类似于手机的方向)。
I would expect it to return portrait, and this is causing problems. 我希望它能返回肖像,这会引起问题。
How can I get the true orientation of the ViewController
and not the device in this case? 在这种情况下,如何获取
ViewController
而不是设备的真实方向?
You need to override your UINavController to set the orientation in portrait when you want. 您需要覆盖UINavController以便在需要时以纵向设置方向。 It's that Vihba means.
这就是Vihba的意思。
The problem is that navController keeps orientation of last view... 问题是navController保持最后一个视图的方向...
**Use this code ***** **使用此代码*****
Also you can refer following link: How to force a UIViewController to Portrait orientation in iOS 6 您也可以参考以下链接: 如何在iOS 6中将UIViewController强制为纵向
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.