Cocoa touch 如何让我的应用程序在导航过程中防止切换回纵向模式?

Cocoa touch 如何让我的应用程序在导航过程中防止切换回纵向模式?,cocoa-touch,Cocoa Touch,当用户移动iPhone时,“我的视图”会在纵向和横向模式之间进行适当切换,使用以下代码不会出现问题: -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrai

当用户移动iPhone时,“我的视图”会在纵向和横向模式之间进行适当切换,使用以下代码不会出现问题:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait || 
        interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

问题是,如果他们在旋转到横向模式后按下一个按钮将他们带到另一个屏幕,那么下一个屏幕将返回到纵向模式,并且状态栏正确地保持在横向模式。如何在加载视图时检测iPhone当前处于哪种模式,以便我可以运行“更改视图方向”命令以适当地更改视图方向?

在设备方向更改之前,会向您的视图控制器发送以下消息:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
toInterfaceOrientation是旋转后应用程序用户界面方向的状态