xcode iOS8上的iPhone界面方向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24907239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:15:24  来源:igfitidea点击:

iPhone Interface Orientation on iOS8

iphoneobjective-cxcodeios8

提问by Cutetare

I have been trying to do this for 2 weeks, and just found out the reason it's not working:

我一直在尝试这样做 2 周,才发现它不起作用的原因:

Deprecated APIs

The following APIs are deprecated:

The UIViewController methods and properties for interface orientation. Traits and size classes replace them, as described in Unified Storyboards for Universal Apps.

From what's new in iOS 8

已弃用的 API

以下 API 已弃用:

界面方向的 UIViewController 方法和属性。特性和大小类取代了它们,如通用应用程序的统一故事板中所述。

来自 iOS 8 的新功能

What I need is: a FirstViewController, which is the rootViewControllerto my navigationController. The FristViewControllershould be onlyavailable in Portrait mode (not ever ever ever displayed in Landscape).

我需要的是: a FirstViewController,这是rootViewController我的navigationController. 本FristViewController在人像模式(不是永远永远永远显示在景观)可用。

Then there are a few intermediate ViewControllers in the navigation stack (which support both orientations), until I reach a LastViewController, which should be available onlyin LandscapeRight mode (and never ever ever in portrait, or another mode).

然后导航堆栈中有一些中间 ViewControllers(支持两种方向),直到我到达 a LastViewController,它应该在 LandscapeRight 模式下可用(永远不会在纵向或其他模式下)。

I have been trying with the following CustomNavigationController, but apparently things changed in iOS8, and I can't get it to work:

我一直在尝试以下方法CustomNavigationController,但显然在 iOS8 中发生了变化,我无法让它工作:

- (BOOL)shouldAutorotate { // Available in iOS 6.0 and later
    return YES; //  // May use topViewController's, but in this app it always returns YES
}

- (NSUInteger)supportedInterfaceOrientations { // Available in iOS 6.0 and later
    if (self.topViewController != nil)
        return [self.topViewController supportedInterfaceOrientations];
    else
        return [super supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { // Available in iOS 6.0 and later
    if (self.topViewController != nil)
        return [self.topViewController preferredInterfaceOrientationForPresentation];
    else
        return [super preferredInterfaceOrientationForPresentation];
}

Thanks!

谢谢!

回答by matt

The problem you are having has nothing whatever to do with iOS 8. Here are some points to note:

您遇到的问题与 iOS 8 无关。以下是一些注意事项:

  • You have misunderstood the note about what's deprecated. Only methods with names like willRotateare deprecated, and you are not using them anyway.

  • Nothing has changedwith regard to how supportedInterfaceOrientationsworks. Make sure you test with beta 4, though, because there was a bug in betas 1-3 that prevented presented view controller orientations from working correctly.

  • "Then there are a few intermediate ViewControllers in the navigation stack (which support both orientations), until I reach a LastViewController, which should be available only in LandscapeRight"... That is impossible, but not because of iOS 8. What you are describing has been illegal since iOS 6! You cannothave different forced orientations for different view controllers in a navigation stack. Only a presented view controllercan force rotation (as I have explained here and in many other answers: https://stackoverflow.com/a/21616025/341994).

  • 您误解了有关已弃用内容的说明。只有名称为 like 的方法willRotate被弃用,而且您无论如何都不会使用它们。

  • 一切都没有改变关于如何supportedInterfaceOrientations工作。但是,请确保您使用 beta 4 进行测试,因为 beta 1-3 中存在一个错误,导致呈现的视图控制器方向无法正常工作。

  • “然后在导航堆栈中有一些中间的 ViewControllers(支持两种方向),直到我到达 LastViewController,它应该只在 LandscapeRight 中可用”......这是不可能的,但不是因为 iOS 8。你是什么自 iOS 6 以来,描述一直是非法的!你不能有一个导航堆栈不同的视图控制器不同的强迫方向。只有呈现的视图控制器才能强制旋转(正如我在此处和许多其他答案中所解释的:https: //stackoverflow.com/a/21616025/341994)。

回答by Fabian

Implement - (NSUInteger)supportedInterfaceOrientationsappropriately in each of the view controllers in the navigation stack. It does not matter what the UINavigationController's supported orientations are. It ought to respect the supported orientations of its displayed view controller.

- (NSUInteger)supportedInterfaceOrientations在导航堆栈中的每个视图控制器中适当地实现。UINavigationController 支持的方向是什么并不重要。它应该尊重其显示的视图控制器支持的方向。

Also make sure that the allthe necessary orientations are checked in your target's "General -> Deployment Info" configuration section.

还要确保在目标的“常规 -> 部署信息”配置部分中检查了所有必要的方向。