2011-02-15 65 views
0

假设我在导航控制器层次结构中有三个视图控制器。视图控制器未以正确的方向显示

这是我如何处理shouldAutorotateToInterfaceOrientation:消息的所有三个视图控制器:

vc1: 
{ return (interfaceOrientation == UIInterfaceOrientationPortrait);} 

vc2: 
{ return (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationLandscapeLeft 
    || interfaceOrientation == UIInterfaceOrientationLandscapeRight);} 

vc3: 
{ return (interfaceOrientation == UIInterfaceOrientationPortrait);} 

所以,我最初的视图控制器VC1显示在肖像模式。如果设备旋转,则没有任何反应,这是正确的。然后我将vc2放到堆栈上,最初它以纵向显示。我旋转设备,vc2进入横向模式,这是正确的。而其余的,在横向模式下为VC2,我弹出VC2从堆栈,回去VC1,并VC1显示在肖像模式 - 这也是正确的。

所以现在是这个问题。

VC1显示在肖像,流行到VC2,并旋转看到横向视图。然后,弹出到vc3vc3滑动横向模式,即使它只支持纵向。

我不知道为什么会发生这种情况,或者如何对付它。换句话说,每当回到vc1时,它只会自动以纵向显示,但vc3自动显示以前的vc使用的任何方向。但是你可以看到我对vc1和vc3使用相同的代码,所以对我来说没有意义。

任何帮助将大大感激!

+0

“我使用VC1和VC1相同的代码”。你的意思是vc1和vc3,对吧?你可能想编辑它。 – 2011-02-15 14:33:21

+0

是的,谢谢你,我的意思是 “VC1和VC3”,我编辑的问题... – bpatrick100 2011-02-15 14:42:11

回答

0

您是如何确定设备方向的?

UIDeviceOrientation指的是err设备的方向,应该与UIDeviceOrientation ...常量进行比较。

UIInterfaceOrientation引用接口的方向。它通过读取statusBar的方向来确定,并且应该与UIInterfaceOrientation进行比较。

相关问题