iOS6中旋转的略微改变(浅析)
在ios6.0中shouldAutorotateToInterfaceOrientation:几乎不在起作用了,ios使用shouldAutorotate来控制旋转效果。
我测试ios6.0真正起作用的旋转有三种:
1.采用info.plist的UISupportedInterfaceOrientations来控制方向
2.是直接在UIWindow中加视图,这种方法可以脱离info.plist的控制,shouldAutorotate来自定义方向。
3.使用rootViewController添加shouldAutorotate方法,但是受info.plist的限制。
以上的方法都限制于顶层视图控制,如果要在子视图控制中添加旋转效果,则需要在顶层视图控制器中开启shouldAutorotate方法,在子视图控制器就可以使用
- (NSUInteger)supportedInterfaceOrientations{}
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil] autorelease]; self.window.rootViewController = self.mainViewController; self.mainViewController.window = self.window; [self.window makeKeyAndVisible]; // 直接添加视图来控制 // self.testVC = [[[testViewController alloc] initWithNibName:@"testViewController" bundle:nil] autorelease]; //[self.window addSubview:self.testVC.view]; return YES; }
顶层视图控制器开启旋转
//MainViewController中开启旋转 - (BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }
添加一个子视图
- (IBAction)showInfo:(id)sender { testViewController *vc = [[testViewController alloc] initWithNibName:@"testViewController" bundle:nil]; //添加子视图 [self presentViewController:vc animated:YES completion:nil]; }
子视图控制器直接使用
//- (BOOL)shouldAutorotate //{ // return YES; //} // testViewController中直接使用 -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }