【发布时间】:2016-08-15 15:34:55
【问题描述】:
在我们的应用中,有一个 ViewController 应该只在纵向模式下可用,因此我们使用了通常的方法来确保只有这种模式有效:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
但是如果用户之前处于横向模式,然后切换到这个特定的 ViewController,它不会自动旋转到纵向模式。因此,我们正在寻找一种强制纵向模式的方法并发现了这一点:
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
它工作正常,但由于它不是官方的做事方式,我们现在或将来可能会被拒绝。
有没有办法通过非私有 API 实现相同的结果?
编辑:我特意问的是如何避免使用这个问题 (How do I programmatically set device orientation in iOS7?) 中发布的解决方案,那么它怎么可能是重复的呢?
【问题讨论】:
-
检查这个stackoverflow.com/questions/38308919/…,我可以告诉你,我在 Appstore 中有一个应用程序具有这种行为并且完全被接受
标签: ios objective-c uiviewcontroller device-orientation