UIViewController不会旋转到横向

在很多情况下需要旋转控制器而不工作。 现在我有问题的反面:它正在旋转,我想禁用。

在那个ViewController中我有这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); } 

但它是自动旋转的,因为不是这个UIViewController被询问,而是他的父UI树。 也许这是问题。 所有情况下,根控制器都必须返回“是”,因为堆栈上还有其他一些UIViewController,它们必须具有Portait / Landscape支持。

我不能/不想触摸其他部分,因为…有几个原因,例如:应用程序是巨大的,有很多知道的错误,我不想让1和testing1一周,其他的是最后期限。

请不要暗示它不应该是这样的,必须改写。 我知道。

如何处理这个控制器强制Portait?

请仔细阅读粗体文本: 不能强制整个应用程序只支持Portait for 1视图控制器,堆栈上有很多!

尝试在属性文件中将应用程序支持的界面方向标记为纵向。 但是,当然在那个函数中,你只需要在视图控制器上返回YES来允许旋转。 但是当你把它推回栈中时,其他视图应该是肖像。

肖像只有方向

检测风景旋转并旋转到Portait:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { UIInterfaceOrientation appOrientation = [UIApplication sharedApplication].statusBarOrientation; float width = self.view.bounds.size.width; float height = self.view.bounds.size.height; //NSLog(@"width %3.0f, height: %3.0f", width, height); if((fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){ // if is rotated from Portait: if((appOrientation == UIInterfaceOrientationLandscapeLeft || appOrientation == UIInterfaceOrientationLandscapeRight)){ // to Landscape: CGAffineTransform transform = self.view.transform; transform = CGAffineTransformRotate(transform, -(M_PI / 2.0)); self.view.transform = transform; [self.view setBounds:CGRectMake(0, 0, height, width)]; } } else { // it is rotated from Landscape: if((appOrientation == UIInterfaceOrientationPortrait || appOrientation == UIInterfaceOrientationPortraitUpsideDown)){ // to Portrait: CGAffineTransform transform = self.view.transform; transform = CGAffineTransformRotate(transform, +(M_PI / 2.0)); self.view.transform = transform; [self.view setBounds:CGRectMake(0, 0, height, width)]; } } } 

这不是最好的编程范例,但它的确有诀窍。

有人写类似的接受他的答案,或者写一个更好的方法,如果可以的话!