【问题标题】:Presented UIViewController refuses to lay out with landscape orientation呈现的 UIViewController 拒绝横向布局
【发布时间】:2015-07-28 20:52:45
【问题描述】:

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

- (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)?

谢谢。

【问题讨论】:

    标签: ios objective-c iphone uiviewcontroller uiinterfaceorientation


    【解决方案1】:

    这是一个非常愚蠢的错误,但万一其他人犯了这个错误并在这里结束,这就是问题所在。

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多