在iOS 6中,UIViewController可以支持比其父接口更多的接口方向吗? [英] Can a UIViewController support more interface orientations than its parent in iOS 6?

查看:188
本文介绍了在iOS 6中,UIViewController可以支持比其父接口更多的接口方向吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 6中对自动旋转的更改似乎让这非常困难或不可能。他们似乎在推动子视图控制器不应该覆盖其父视图控制器的自动旋转行为的理念。这使我很难完成我想要做的事情:

The changes to auto-rotation in iOS 6 seems to have made this incredibly difficult, or impossible. They seem to be pushing the philosophy that a child view controller should not have to override the auto-rotation behavior of its parent view controller. This makes it difficult to accomplish what I am trying to do:


  • 我有一个必须显示肖像的视图控制器。

  • 它推动另一个视图控制器模态,这是一个简单的图像查看器,但我希望这个视图控制器能够旋转到任何纵向或横向(显而易见的原因)

  • 当子视图控制器被解除时(无论其当前方向如何),父视图控制器应保持纵向方向


来自UIViewController课程参考的相关Apple文档



在iOS 6中,您的应用程序支持应用程序的Info.plist文件中定义的界面方向。视图控制器可以覆盖supportedInterfaceOrientations方法以限制支持的方向列表。通常,系统仅在窗口的根视图控制器或呈现的视图控制器上调用此方法以填充整个屏幕;子视图控制器使用由父视图控制器为其提供的窗口部分,不再直接参与有关支持哪些旋转的决策。应用程序的方向蒙版和视图控制器的方向蒙版的交集用于确定视图控制器可以旋转到哪个方向。

Relevant Apple Documentation from UIViewController class reference

In iOS 6, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Generally, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate in directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.

我已经考虑过使用变换来模拟子视图控制器中的旋转,但说实话,我觉得应该有更好的方法,并且如果可能,我希望避免这种情况。

I've thought about using transforms to simulate rotation in the child view controller, but honestly, I feel like there should be a better way, and would like to avoid that if at all possible.

似乎任何子视图控制器都支持接口方向,其父视图控制器(以模态或其他方式呈现)现在也必须支持该接口方向。

It seems that any in order for any child view controller to support an interface orientation, its parent view controller (presented modally or otherwise) must now also support that interface orientation.

我在这里错过了一些简单的东西吗?这看起来像是荒谬的吗?

Am I missing something simple here? Is this as ridiculous as it seems?

推荐答案

我今天正在处理类似的问题并且达到了这个目的:

I'm dealing with similiar problem today and got to this:

在父视图中,我检查是否分配了孩子(因此在我的案例中显示)。如果是,则代码允许任何方向,如果不允许则仅允许方向。类似于:

In parent view I check if the child is allocated (and thus shown in my case). If yes the code allows any orientation, if no then only landscape. Something like:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    bool result;

    if (self.photoViewController)
    {
        result = YES;
    }
    else
    {
        result = (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }

    return result;
}

- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger result;

    if (self.photoViewController)
    {
        result = UIInterfaceOrientationMaskAll;
    }
    else
    {
        result = UIInterfaceOrientationMaskLandscapeLeft+UIInterfaceOrientationMaskLandscapeRight;
    }

    return result;
}

孩子这个功能看起来有点不同:

in child this functions look a bit different:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

这让我遇到你在评论中提到的同样的问题 Robotic Cat的答案:当孩子被解雇时,父视图控制器可以在错误的方向找到它。

This got me to the same problem that you mention in your comment to Robotic Cat's answer:parent view controller can find it self in wrong orientation when child is dismissed.

此代码(感谢 Corey Floyd的片段)强制父级重定向。

This code (thanks to Corey Floyd's snippet) forces the parent to reorient.

UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:c animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];

它应放在删除子视图控制器的点之后。这个是为iOS 6.0编写的,您也可以使用原始链接中的代码。

It should be placed after the point where child view controller gets removed. This one is written for iOS 6.0, you can also use the code from the original link.

这篇关于在iOS 6中,UIViewController可以支持比其父接口更多的接口方向吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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