【问题标题】:iOS - How to force Portrait mode when currently in Landscape modeiOS - 当前处于横向模式时如何强制纵向模式
【发布时间】: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?) 中发布的解决方案,那么它怎么可能是重复的呢?

【问题讨论】:

标签: ios objective-c uiviewcontroller device-orientation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2015-06-23
    • 2014-03-04
    相关资源
    最近更新 更多