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

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

问题描述

在 iOS6 中,不推荐使用 shouldAutorotateToInterfaceOrientation.我尝试使用 supportedInterfaceOrientationsshouldAutorotate 使应用程序正常工作以进行自动旋转,但失败了.

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 , According to your needs ,another related method :

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

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

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