iPhone开发笔记(21)iOS 6旋转问题解决方法汇总

    iOS 6的SDK改变了以往控制UIViewController的方式,为了兼容iOS 5和iOS 6,需要对代码进行必要的调整。因为每个应用的结构不一样,所以再这篇文章中,我只讲了我所遇到的UITabBarController+UINavigationController的应用结构。此外,我也在最后列出了一些情况的解决方法,如果本文的方法对你遇到的问题不起作用,那么可以试试列出的连接给出的解决方法。

    1、在工程的设置界面将设备支持的旋转方向开关开启如下图:

    

    2、设置window的rootViewController

    在AppDelegate.h中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ......
    self.window.rootViewController = tabBarController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
}

    3、添加UITabBarController的Category

@implementation UITabBarController (Background)

-(BOOL)shouldAutorotate
{
    //这里我是首先从全局的角度设置自动旋转为NO,因为不需要每个UIViewController都自动旋转。
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    //全局设置为
    return UIInterfaceOrientationMaskPortrait;
}

@end

@implementation AppDelegate
    4、在需要开启自动旋转的UIViewController的.m文件中添加如下代码

//iOS 5以前的旋转控制方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return ((interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) &&
                (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) &&
                (interfaceOrientation != UIInterfaceOrientationLandscapeRight));
    } else {
        return YES;
    }
}

/iOS 6的旋转控制方法
- (BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
    5、其他情况的解决方法参考

http://stackoverflow.com/questions/12522903/uitabbarcontroller-rotation-issues-in-ios-6



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值