我们如何在iOS 8中指定应用程序方向? [英] How do we dictate app orientation in iOS 8?

查看:170
本文介绍了我们如何在iOS 8中指定应用程序方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7中,我们说:

In iOS 7 we said:

// ViewController1:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate {
    return YES;
}

// ViewController2, presented by modal segue from button in ViewController1

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate {
    return YES;
}

结果是应用程序在视图控制器1和纵向中出现在横向在视图控制器2中。

The result was that the app appeared in landscape in view controller 1 and in portrait in view controller 2.

该代码在iOS 7中运行良好,包括Xcode 6中的iOS 7模拟器。但它在iOS 8中不再有效。有两个问题:

That code works fine in iOS 7, including the iOS 7 simulators in Xcode 6. But it no longer works in iOS 8. There are two problems:


  • 视图控制器1的视图以横向显示,但模拟器不会自动旋转(可能只是模拟器错误) (这是非常重要的部分)视图不会自动调整大小,因此屏幕太窄(右边有一个很大的黑色区域)。

  • View Controller 1's view is appearing in landscape, but the simulator is not automatically rotating (might just be a simulator bug) and (this is the really important part) the view is not automatically being resized, so it is too narrow for the screen (there's a big black area to its right).

视图控制器2的视图与视图控制器1的视图(横向,而不是纵向)的方向相同。

View Controller 2's view is appearing in the same orientation as View Controller 1's view (landscape, not portrait).

因此,视图控制器视图不会自动调整大小以填充屏幕,并且所呈现的视图控制器支持的方向不受尊重。

So view controller views are not automatically resizing to fill the screen, and the presented view controller's supported orientations are not being honored.

那么我们如何支持现在这样做?它与特质集合有关吗?首选内容大小?手动设置状态栏方向?

So how are we supposed to do this now? Does it have to do with trait collections? With preferred content size? With setting the status bar orientation manually?

推荐答案

第一部分(启动到横向)的答案与iOS 7保持不变:一切取决于Info.plist文件中可能的方向的顺序。所以,让我们说View Controller 1说:

The answer to part one (launching into landscape) is unchanged from iOS 7: everything depends on the order of possible orientations in the Info.plist file. So, let's say that View Controller 1 says this:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

如果在信息中首先出现横向信息,我们将连贯地进入景观.plist支持的界面方向:

Then we will coherently launch into landscape if a landscape orientation comes first in the Info.plist's supported interface orientations:

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationPortrait</string>
</array>

iOS 8中一个值得注意的变化是,默认情况下,当我们处于景观状态时,状态栏会被隐藏。但是如果需要,您可以使用适当的覆盖来阻止这种情况:

One noteworthy change in iOS 8 is that by default the status bar is hidden when we're in landscape. But you can prevent this, if desired, with the appropriate override:

-(BOOL)prefersStatusBarHidden {
    return NO;
}

这不回答我问题的第二部分,即如何显示视图控制器时强制旋转。正如我在这个答案中所解释的那样,我的感觉是在iOS 8中这将变得不可能。您的视图控制器和您的视图预计会适应 - 你也是如此。

That doesn't answer the second part of my question, which is how to force rotation when a view controller is presented. As I have explained in this answer, my sense is that this will become impossible in iOS 8. Your view controller and your views are expected to "adapt" — and so are you.

编辑:在种子4中看起来像强制应用程序在视图上旋转的能力控制器演示/解雇正在返回!

It looks like in seed 4 the ability to force app rotation on view controller presentation/dismissal is returning!

这篇关于我们如何在iOS 8中指定应用程序方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆