iOS 6 旋转:supportedInterfaceOrientations 不起作用?

iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)

本文介绍了iOS 6 旋转:supportedInterfaceOrientations 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 iOS 6 SDK 时遇到了这个问题:我有一些应该允许旋转的视图(例如视频视图),而另一些则不允许.现在我知道我必须检查应用程序的 Info.plist 中的所有方向,然后在每个 ViewController 中进行排序,应该发生什么.但它不起作用!应用程序始终旋转到 Info.plist 中给出的方向.

I´m having this issue with iOS 6 SDK: I´m having some views that should be allowed to rotate (e.g. a videoview), and some that don´t. Now I understand I have to check all orientations in the app´s Info.plist and then sort out in each ViewController, what should happen. But it doesn´t work! The app always rotates to the orientations, that are given in the Info.plist.

Info.plist:

Info.plist:

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

任何不应被允许旋转的 ViewController:

any ViewController that shouldn´t be allowed to rotate:

//deprecated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

观察:应用旋转到横向和纵向.任何想法为什么或我做错了什么?

Observation: App rotates to landscape and portrait orientation. Any ideas why or what I´m doing wrong?

干杯,马克

我的最新发现还表明,如果您想在应用程序中的某个位置进行旋转,您必须在项目设置或 Info.plist 中激活所有四个旋转方向.另一种方法是覆盖

My latest findings also indicate, that if you want to have rotation at some point in your app, you have to activate all four rotation directions in your project settings or Info.plist. An alternative to this is to override

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

在您的 AppDelegate 中,它会覆盖 Info.plist.不再可能在 Info.plist 中仅设置 Portrait,然后通过覆盖 shouldAutorotateToInterfaceOrientation 或 supportedInterfaceOrientations 在某些 ViewController 中进行旋转.

in your AppDelegate, which overrides the Info.plist. It isn´t possible anymore to set only Portrait in your Info.plist and then having rotation in some ViewController by overriding shouldAutorotateToInterfaceOrientation or supportedInterfaceOrientations.

推荐答案

如果您的 ViewController 是 UINavigationController 或 UITabBarController 的子级,那么您的问题就是父级.您可能需要对该父视图控制器进行子类化,只需覆盖您在问题中显示的那些 InterfaceOrientation 方法

If your ViewController is a child of a UINavigationController or UITabBarController, then it is the parent that is your problem. You might need to subclass that parent view controller, just overriding those InterfaceOrientation methods as you've shown in your question

仅纵向 TabBarController 的示例

Example for portrait only TabBarController

           @interface MyTabBarController : UITabBarController
            {
            }
            @end

            @implementation MyTabBarController

            // put your shouldAutorotateToInterfaceOrientation and other overrides here        
            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
                return (interfaceOrientation == UIInterfaceOrientationPortrait);
            }

            - (NSUInteger)supportedInterfaceOrientations{ 
                return UIInterfaceOrientationMaskPortrait; 
            } 

        @end

这篇关于iOS 6 旋转:supportedInterfaceOrientations 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iOS 6 旋转:supportedInterfaceOrientations 不起作用?

基础教程推荐