ios - 如何在不将另一个 View Controller 插入堆栈的情况下支持 iOS 7 中的多个屏幕方向?

标签 ios objective-c uiinterfaceorientation

我一直在尝试让多个方向与单个 View Controller 一起工作。目前它检查设备方向和 View Controller 。然后根据它是横向还是纵向进行切换。问题是它在纵向模式下工作正常,但由于它在横向模式下将另一个 View 推送到堆栈上,后退按钮链接到纵向 View 而不是我们想要返回的实际屏幕(这是进一步的步骤) .

if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        self.navigationController.visibleViewController == self)
    {
        self.landscapeViewController =
        [self.storyboard instantiateViewControllerWithIdentifier:@"view_landscape"];

        [self.navigationController pushViewController:self.landscapeViewController
                                             animated:NO];

    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
             self.navigationController.visibleViewController == self.landscapeViewController)
    {
        [self.navigationController popViewControllerAnimated:NO];
    }

我不能以模态方式呈现横向 View Controller ,因为涉及到导航 Controller 。

另一件事是我为每个方向实例化相同的 View Controller (使用相同的类但链接到 Storyboard中的不同标识符)。

最佳答案

您尝试做的事情真的很糟糕,并且违背了 Apple 的做事方式。

有一种称为 Autolayout 的东西,您可以使用它设计一个 View 以在横向和纵向模式下工作。

关于ios - 如何在不将另一个 View Controller 插入堆栈的情况下支持 iOS 7 中的多个屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20263215/

相关文章:

ios - 当 UITabBarController 在屏幕上显示第一个选项卡时调用什么方法? viewDidAppear 不起作用

objective-c - xcode 中泄漏仪器的准确性

ios - iOS 方向问题

ios - 使用 URL 作为名称来保存文件

ios - AVPlayerViewController 问题

javascript - 如果缓慢离开屏幕,Touchend iOS 不会触发

iphone - UIActivity子类打开webview

ios - AVPlayer 适用于模拟器,但不适用于设备

ios - 如何在 iOS 8 中为特定 Controller 禁用自动旋转?

ios - 以编程方式允许某些 View Controller 的纵向和横向方向