提出的UIViewController拒绝以横向方向进行布局

时间:2015-07-28 20:52:46

标签: ios objective-c iphone uiviewcontroller uiinterfaceorientation

我正在更新一个已有5年历史的应用程序(最初是为iOS 3编写的!)。我在使用autolayout和解决弃用警告方面取得了不错的进展。但是,当设备旋转时用于呈现不同视图控制器的旧技术不再可靠地工作。

- (void)orientationChanged:(NSNotification *)notification {
            UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
            if (deviceOrientation == UIInterfaceOrientationLandscapeRight && !showingOtherVC) {
                // switch to other VC
                othervc.modalPresentationStyle = UIModalPresentationOverFullScreen;
                [self presentViewController:othervc animated:YES completion:nil];
                [self resignFirstResponder];
             }

另一个视图控制器确实出现了,但它是横向布局的,对于纵向屏幕,而不是横向,即使设备处于横向方向。

如何以一种相当简单的方式更新它(即,不是在Swift中重写,而不是使用故事板重构应用程序 - Xcode似乎不通过复制/粘贴来促进)?并且,为了这个问题可能发生的其他人的利益,如果我从头开始写这个结果,那么实现这个结果的更正确的方法是什么(新的VC改变方向)?

谢谢。

1 个答案:

答案 0 :(得分:1)

这是一个非常愚蠢的错误,但是如果其他人成功并最终在这里,这就是问题所在。

而不是正确返回掩码常量:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskLandscapeRight);
}

我正在返回另一个自动完成给我的常量:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return (UIInterfaceOrientationLandscapeRight);
}