iPhone屏幕旋转

iPhone屏幕内容旋转

在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。

但是iOS 6里屏幕旋转改变了很多,之前的 shouldAutorotateToInterfaceOrientation 被列为 DEPRECATED 方法,从IOS6开始使用新的方法来控制屏幕内容的旋转

操作方法

1:定义一个UINavigationController的子类,然后添加下面的代码

- (BOOL)shouldAutorotate

{

    return self.topViewController.shouldAutorotate;

}

 

- (NSUInteger)supportedInterfaceOrientations

{

    returnself.topViewController.supportedInterfaceOrientations;

}

 

2:将window.RootController 制定为这个自定义的类

 

3:重载下面两个方法来控制页面内容是否随着屏幕旋转

-(BOOL)shouldAutorotate

{

    return NO;

}

 

-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskPortrait;

}

Jason

2014年02月14日

原文地址:https://www.cnblogs.com/xingchen/p/3549590.html