iOS 6轮换:supportedInterfaceOrientations不起作用? [英] iOS 6 rotations: supportedInterfaceOrientations doesn´t work?

查看:1271
本文介绍了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;
}

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

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

干杯,
Marc

Cheers, Marc

编辑:我的最新发现还表明,如果您希望在应用中的某个位置进行轮换,则 可以激活项目设置或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

,它会覆盖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不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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