简体   繁体   English

iOS8上的iPhone接口方向

[英]iPhone Interface Orientation on iOS8

I have been trying to do this for 2 weeks, and just found out the reason it's not working: 我已经尝试了2个星期,但是发现它不起作用的原因是:

Deprecated APIs 弃用的API

The following APIs are deprecated: 不推荐使用以下API:

The UIViewController methods and properties for interface orientation. 用于界面定向的UIViewController方法和属性。 Traits and size classes replace them, as described in Unified Storyboards for Universal Apps . 特质和大小类将其替换,如Universal Apps的统一情节提要中所述。

From what's new in iOS 8 来自iOS 8的新功能

What I need is: a FirstViewController , which is the rootViewController to my navigationController . 我需要的是: FirstViewController ,它是我的navigationControllerrootViewController The FristViewController should be only available in Portrait mode (not ever ever ever displayed in Landscape). 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 only in LandscapeRight mode (and never ever ever in portrait, or another mode). 然后,在导航堆栈中有一些中间ViewControllers(都支持两种方向),直到到达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! 谢谢!

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 willRotate are deprecated, and you are not using them anyway. 仅弃用名称如willRotate方法,并且无论如何您都不会使用它们。

  • Nothing has changed with regard to how supportedInterfaceOrientations works. 关于supportedInterfaceOrientations工作方式, 没有任何改变 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. 不过,请确保您使用Beta 4进行测试,因为Beta 1-3中存在一个错误,导致所显示的视图控制器方向无法正常工作。

  • "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! “然后,在导航堆栈中有一些中间ViewControllers(支持两个方向),直到我到达LastViewController,它应该仅在LandscapeRight中可用”。这是不可能的,但由于iOS 8的原因,这是不可能的。自iOS 6起,描述就不合法了! You cannot have different forced orientations for different view controllers in a navigation stack. 导航堆栈中的不同视图控制器不能具有不同的强制方向。 Only a presented view controller can force rotation (as I have explained here and in many other answers: https://stackoverflow.com/a/21616025/341994 ). 仅存在的视图控制器可以强制旋转(正如我在此处以及其他许多答案中所解释的: https : //stackoverflow.com/a/21616025/341994 )。

Implement - (NSUInteger)supportedInterfaceOrientations appropriately in each of the view controllers in the navigation stack. 在导航堆栈中的每个视图控制器中适当地实现- (NSUInteger)supportedInterfaceOrientations It does not matter what the UINavigationController's supported orientations are. UINavigationController支持的方向是什么都没有关系。 It ought to respect the supported orientations of its displayed view controller. 它应该尊重其显示的视图控制器的受支持方向。

Also make sure that the all the necessary orientations are checked in your target's "General -> Deployment Info" configuration section. 还要确保在目标的“常规->部署信息”配置部分中选中了所有必需的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM