iOS-当前处于横向模式时如何强制纵向模式

iOS-当前处于横向模式时如何强制纵向模式,ios,objective-c,uiviewcontroller,device-orientation,Ios,Objective C,Uiviewcontroller,Device Orientation,在我们的应用程序中,有一个ViewController只能在纵向模式下使用,因此我们使用了通常的方法来确保只有此模式有效: -(UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationPortraitUpsideDown; } 但是,如果用户以前处于横向模式,然后切换到此特定的ViewCont

在我们的应用程序中,有一个ViewController只能在纵向模式下使用,因此我们使用了通常的方法来确保只有此模式有效:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
但是,如果用户以前处于横向模式,然后切换到此特定的ViewController,则它不会自动旋转到纵向模式。因此,我们正在寻找一种强制肖像模式的方法,并发现:

[[UIDevice currentDevice] setValue:
 [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
                            forKey:@"orientation"];
它工作得很好,但因为它不是一种正式的做事方式,我们现在或将来可能会被拒绝

是否有一种方法可以实现相同的结果,但使用非私有API


编辑:我特别想问的是如何避免使用这个问题()中发布的解决方案,那么它怎么可能是重复的呢?

shouldautorotate方法应该为该视图控制器返回否。如果这不起作用,则使用post通知来管理方向。

检查此项的可能重复项,我可以告诉您,我在Appstore中有一个应用程序具有此行为,并且完全可以接受