了解iOS 6界面方向更改 [英] Understanding iOS 6 Interface orientation change

查看:91
本文介绍了了解iOS 6界面方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已添加:
我看到我的问题经常在没有赞成票的情况下被查看,因此我认为你们没有得到你搜索的内容。重定向到一个关于
非常好答案的问题如何处理iOS6中的方向更改



方向更改的具体要求:
限制轮换



欢迎Upvotes :)






我已经从Master Detail模板创建了一个新项目,并试图以横向方向启动它。
如你所知



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation



方法已被弃用,我们必须使用



- (NSUInteger)supportedInterfaceOrientations



和/或



- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation



这是我的代码:

   - (NSUInteger)supportedInterfaceOrientations {
NSLog(@支持叫);
返回UIInterfaceOrientationMaskAll; //实际上是默认值
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
NSLog(@preferred called); //这个方法永远不会被调用。为什么?
返回UIInterfaceOrientationLandscapeRight;
}

正如你所看到的,我试图在首选方法中返回横向方向但是它永远不会被称为。
p.s.文档说明:


讨论系统在显示视图
控制器全屏时调用此方法。当您的视图
控制器支持两个或更多方向时,您实现此方法,但内容在其中一个方向上最好显示为



如果您的视图controller实现了这个方法,然后在显示时,
它的视图以首选方向显示(尽管稍后可以将
旋转到另一个支持的旋转)。如果你没有实现
这个方法,系统会使用状态栏的当前
方向显示视图控制器。


所以,问题是:为什么永远不会调用prefferredOrientation方法?我们应该如何在不同的控制器中处理不同的方向?谢谢!
P.S不要将问题标记为重复。我已经调查了所有类似的问题,他们没有我的答案。

解决方案

关于preferredInterfaceOrientationForPresentation



preferredInterfaceOrientationForPresentation 永远不会被调用,因为它不是呈现的视图控制器。这里没有涉及演示。



呈现和演示不是一些模糊的术语,意思是出现。这些是精确的技术术语,意味着这个视图控制器可以通过调用 presentViewController:animated:completion:来实现。换句话说,只有当我们以前称之为模态视图控制器时,此事件才会到达。



嗯,您的视图控制器不是模态视图控制器;它是 presentViewController一起玩:动画:完成:。所以没有涉及演示,因此 preferredInterfaceOrientationForPresentation 在这里无关紧要。



我非常明确关于这一点,因为我认为很多人会像你一样被混淆或误导。所以也许这个笔记会帮助他们。



启动到横向



在iOS 6中,支持的界面方向 Info.plist中的密钥比以前更加重要。启动到所需方向的整体问题的解决方案是:


  1. 确保信息中的支持的界面方向 .plist列出所有方向,您的应用


  2. 确保在支持的界面方向中,



  3. 这就是它的全部。实际上,您不应该将任何代码放入根视图控制器来管理初始方向。


    ADDED: I see that my question is viewed often without upvotes so I decided that you guys do not get what you search. Redirecting you to question that has really nice answer about How to handle orientation changes in iOS6

    Specific demands to orientation changes: Restricted rotation

    Upvotes are welcome :)


    I've created a new project from Master Detail template and trying to start it with landscape orientation. As you know the

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

    method is deprecated and we must use

    - (NSUInteger)supportedInterfaceOrientations

    and/or

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

    Here's my code:

    - (NSUInteger)supportedInterfaceOrientations {
        NSLog(@"supported called");
        return UIInterfaceOrientationMaskAll;//Which is actually a default value
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
        NSLog(@" preferred called");//This method is never called. WHY?
        return UIInterfaceOrientationLandscapeRight;
    }
    

    As you can see I'm trying to return landscape orientation in preferred method but it is never called. p.s. documentation states:

    Discussion The system calls this method when presenting the view controller full screen. You implement this method when your view controller supports two or more orientations but the content appears best in one of those orientations.

    If your view controller implements this method, then when presented, its view is shown in the preferred orientation (although it can later be rotated to another supported rotation). If you do not implement this method, the system presents the view controller using the current orientation of the status bar.

    So, the question is: Why the prefferredOrientation method is never get called? And how should we handle different orientations in different controllers?. Thanks! P.S don't mark the question as duplicate. I've investigated all similar questions and they do not have answer for mine.

    解决方案

    About preferredInterfaceOrientationForPresentation

    preferredInterfaceOrientationForPresentation is never called because this is not a "presented" view controller. There is no "presentation" involved here.

    "Presented" and "presentation" are not some vague terms meaning "appears". These are precise, technical terms meaning that this view controller is brought into play with the call presentViewController:animated:completion:. In other words, this event arrives only if this is what we used to call a "modal" view controller.

    Well, your view controller is not a modal view controller; it is not brought into play with presentViewController:animated:completion:. So there is no "presentation" involved, and therefore preferredInterfaceOrientationForPresentation is irrelevant here.

    I'm being very explicit about this because I'm thinking that many folks will be confused or misled in the same way you were. So perhaps this note will help them.

    Launch into Landscape

    In iOS 6, the "Supported Interface Orientations" key in your Info.plist is taken much more seriously than previously. The solution to your overall problem of launching into a desired orientation is:

    1. Make sure that "Supported Interface Orientations" in your Info.plist lists all orientations your app will ever be allowed to assume.

    2. Make sure that the desired launch orientation is first within the "Supported Interface Orientations".

    That's all there is to it. You should not in fact have to put any code into the root view controller to manage the initial orientation.

    这篇关于了解iOS 6界面方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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