ios6 autorotation portraitupsidedown到肖像

请不要build议我在1个版本的ios 4.3-6.0上进行轮换是个不错的主意,因为我多次告诉过,并没有听我说。

在项目设置中,我已经设置了所有的接口方向来支持,只是可以肯定的。

现在我正在用iphone4testingios6。 从应用程序委托开始,它是一个代码,如下所示:

mainController = [[MainViewController alloc] initWithNibName:nil bundle:nil]; navigationController=[[RotatingNavigationController alloc] initWithRootViewController:mainController]; navigationController.navigationBar.hidden =true; // ios: 4 and 5 //[window addSubview:navigationController.view]; //ios6: window.rootViewController = navigationController; [window makeKeyAndVisible]; 

所以我做了2个自定义的类,在自动旋转的情况下推荐它们,并为他们解决了这个问题。

RotatingNavigationController是一个自定义的UINavigationController有一些难看的代码,但是我从这个论坛收集了这个部分,所以应该允许它发布它:

 @implementation RotatingNavigationController - (id)init { self = [super init]; if (self) { self.view.autoresizesSubviews = YES; [self.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)]; } return self; } // ios6 require this method for rotation detection, available from ios5, ios4.3 not available: sux //- (void)viewWillLayoutSubviews //{ //UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation; //[[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil]; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; /* if(UIInterfaceOrientationIsLandscape(statusBarOrientation)){ [self willRotateToInterfaceOrientation: statusBarOrientation duration: 0.3 ]; } else{ [self willRotateToInterfaceOrientation: statusBarOrientation duration: 0.3 ]; } */ //} //ios 4.3 and ios 5.0, at ios6 it isn't called by iOS...sux - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ [self.visibleViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; } // //ios 4.3 and ios 5.0, at ios6 need different methods, which sux - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } //Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods. // ios6 - (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } // ios6 - (BOOL)shouldAutorotate { return YES; } // ios6 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; } @end 
  • 这应该适当地生成自动通知,我认为他这样做是他的工作。

MainViewController是一个自定义的UIViewController

只是为了确保我已经复制粘贴的代码:

 // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations // return (interfaceOrientation == UIInterfaceOrientationPortrait); return YES; } // ios6: - (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } // ios6 - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskPortrait; } 

他的工作是根据设备状态(旋转)来改变不同的UIViewController,

我有一个菜单屏幕,它有不同的XIB,但H和M文件(因为有不同的元素,它不出现在Portait或景观(我没有权力改变整个架构)

代码的一部分 – 这里应该是一些问题,我想是在这个Maincontroller下面:

 #pragma mark #pragma mark Rotation - (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation; if(deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown){ if(debug){ NSLog(@"Nothing to change because it is gone to Flat"); } return; } NSArray *viewControllers = [self.navigationController viewControllers]; if (UIDeviceOrientationIsLandscape(deviceOrientation)){ //if(debug) // NSLog(@"Portait -> Landscape size : %3.0fw, %3.0fh", self.view.bounds.size.width, self.view.bounds.size.height); id lastviewController = viewControllers.lastObject; // check what is there: if([lastviewController isKindOfClass:[MenuController class]]){ [self.navigationController popViewControllerAnimated:NO]; [self.navigationController pushViewController:menuLandscape animated:NO]; NSLog(@"poped Menu Portrait, pushed Menu Landscape"); } ... else if(UIDeviceOrientationIsPortrait(deviceOrientation)){ //else if(UIInterfaceOrientationIsLandscape(statusBarOrientation)){ //if(debug) // NSLog(@"Landscape -> Portait , size : %3.0fw, %3.0fh", self.view.bounds.size.width, self.view.bounds.size.height); id lastviewController = viewControllers.lastObject; // check what is there: if([lastviewController isKindOfClass:[MenuLandscapeController class]]){ [self.navigationController popViewControllerAnimated:NO]; [self.navigationController pushViewController:menuPortait animated:NO]; } ... 

问题是:景观被取出,并被推倒,当它倒过来,但那个门户不旋转,并显示一个破碎的布局。

我怎么能唤醒那个控制器,告诉他是时候旋转了,因为它不是纵向模式?

感谢任何有关我的build筑改变之外的任何改进问题的build议。

更新:

在应用程序界面并没有帮助添加:

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

来自其他答案的代码: 在这里介绍

UPDATE2:

 UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation; 

由于某些原因,不想采取UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown值,我认为需要解决。

Update3:仔细阅读两次,第三次阅读ios6发行说明

系统通过将应用程序的supportedInterfaceOrientationsForWindow:方法返回的值与最顶级的全屏控制器的supportedInterfaceOrientations方法返回的值相交来确定是否支持方向。

  • 现在再读一遍:)

将此类别添加到不旋转的视图控制器

 @implementation UINavigationController(Rotation) -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } @end