简体   繁体   English

iOS6中的自动旋转

[英]Autorotation in iOS6

I am updating my app for iOS 6 and having issues with the changes to autorotation. 我正在为iOS 6更新我的应用程序,并且对自动旋转的更改存在问题。 My app has a bunch of view controllers and all of them should only support the portrait layout except 1 which should support all 3 orientations except upside down. 我的应用程序有一堆视图控制器,所有这些应该只支持纵向布局,除了1应该支持所有3个方向,除了颠倒。

If I add the application:supportedInterfaceOrientationsForWindow: method to the app delegate do I have to add conditions there to check if im displaying the one VC I want to be able to rotate? 如果我添加application:supportedInterfaceOrientationsForWindow:方法到app委托我是否必须在那里添加条件来检查我是否显示我希望能够旋转的VC?

The documentation states that if I implement supportedInterfaceOrientations on a VC it should override the app delegate method but this doesn't appear to be the case. 该文档指出,如果我在VC上实现supportedInterfaceOrientations ,它应该覆盖app delegate方法,但似乎不是这种情况。 I have an log statement in the method on the child VC and it is called once when the VC loads but its not called when I rotate the device, but the method in the app delegate is. 我在子VC上的方法中有一个日志语句,它在VC加载时调用一次,但在我旋转设备时没有调用,但是app委托中的方法是。

If I completely remove the method from the app delegate the orientation of my VC's seems to be completely dependent on my apps supported interface orientation settings. 如果我从应用程序委托中完全删除该方法,我的VC的方向似乎完全取决于我的应用程序支持的界面方向设置。 This of course seems to be due to the method supportedInterfaceOrientations being called once on creation of the VC but never when the device is rotated. 这当然似乎是由于在创建VC时调用了一次supportedInterfaceOrientations方法,但从未在设备旋转时调用。

Does anyone have any ideas or suggestions? 有没有人有任何想法或建议? It would be much appreciated. 非常感谢。

Replace [window addSubview:viewController.view]; 替换[window addSubview:viewController.view]; with window.rootViewController = viewController; window.rootViewController = viewController;

You also need to override - (BOOL) shouldAutorotate and return "YES". 您还需要覆盖 - (BOOL)shouldAutorotate并返回“YES”。 This makes it so you declare what orientations your VC supports with "supportedInterfaceOrientations" and then on rotation it should call "shouldAutorotate". 这使得您可以使用“supportedInterfaceOrientations”声明VC支持的方向,然后在轮换时应调用“shouldAutorotate”。 If you have any navigation controller or tabbar you may need to subclass those to do the same thing within them. 如果您有任何导航控制器或tabbar,您可能需要将它们子类化以在其中执行相同的操作。 I had this issue recently myself. 我最近自己有这个问题。

try this... 尝试这个...

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{

    if (UIInterfaceOrientationIsLandscape(interfaceOrientation))  
    { 
        // here to  implement landscope code
    }
    else
    {  
        // here to  implement setframePortrait
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM