from:http://blog.sina.com.cn/s/blog_71715bf801019oye.html html
在ios5下画面的旋转都是shouldAutorotateToInterfaceOrientation来控制的,可是这个函数在ios6下不起做用。ios
在ios6下使用supportedInterfaceOrientations、shouldAutorotate来控制。app
若是单一的控制画面那么只须要加在上面两个函数。以下函数
- (BOOL)shouldAutorotate { ui
return YES; spa
} .net
- (NSUInteger)supportedInterfaceOrientations { orm
return UIInterfaceOrientationMaskAll; htm
} blog
若是是含有UINavigationController、UITabBarController的话,那么修改部分就多了。
用其派生类的,在派生类中增长上面的supportedInterfaceOrientations、shouldAutorotate函数。
下面如MyNavigationController就是UINavigationController 的派生类。
修改部分以下
1:在旧的程序中AppDelegate的部分如
定义的 UINavigationController *navigationController;
[window addSubview:[navigationController view]]; //不能旋转
改成
MyNavigationController *myNavigationController;
self.window.rootViewController = self.myNavigationController;
派生类主要部分为
#import "MyNavigationController.h"
@interface MyNavigationController ()
@end
@implementation MyNavigationController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(BOOL)shouldAutorotate
{
return [self.viewControllers.lastObject shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这样就能控制全部的控制画面中的旋转了,固然别忘了在每一个控制画面都增长旋转的函数。
根据多篇文章改写的,目前根据这样的方式,可以解决本身目前的问题,
若是你们还有更好的方式,还须要多指教。
官方