如何让应用程序在iOS 6中完全正常工作以进行自动旋转? [英] How to make app fully working correctly for autorotation in iOS 6?

查看:127
本文介绍了如何让应用程序在iOS 6中完全正常工作以进行自动旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS6中,不推荐使用 shouldAutorotateToInterfaceOrientation 。我尝试使用 supportedInterfaceOrientations shouldAutorotate 来使应用程序正常运行以进行自转但失败。

In iOS6, shouldAutorotateToInterfaceOrientation is deprecated. I tried to use supportedInterfaceOrientations and shouldAutorotate to make app working correctly for autorotation but failed.

这个ViewController我不想旋转,但它不起作用。

this ViewController I don’t want to rotate, but it doesn't work.

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

有什么想法吗?
感谢您提前获得任何帮助!

Any ideas? Thanks for any help in advance!

推荐答案

想出来。

1)子类化UINavigationController (层次结构的顶层视图控制器将控制方向。)
确实将其设置为self.window.rootViewController。

1) subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) did set it as self.window.rootViewController.

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

2)如果你不想让视图控制器旋转

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

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

3)如果你想让它能够旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

BTW,根据您的需要,另一种相关方法:

BTW , According to your needs ,another related method :

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return UIInterfaceOrientationMaskPortrait;
}

这篇关于如何让应用程序在iOS 6中完全正常工作以进行自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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