; 行为奇怪

我有一个通用的应用程序,支持iPad的所有方向,只有iPhone / iPod的potrait。 我的代码看起来有点像这样:

@implementation UIViewController ( interfaceOrientationHack ) - (void) shouldAutorotateToInterfaceOrientation: ( UIInterfaceOrientation ) toInterfaceOrientation { if( iPad ) { return YES; } else if( toInterfaceOrientation == UIInterfaceOrientationPotrait ) { return YES; } else return NO; } @end 

从我的一个控制器中,我启动了一个导航控制器作为模态视图控制器

 [ self presentModalViewController: c animated: YES ]; 

目前的问题是,模态控制器在方向上正确启动,但是当我改变方向时,模态控制器不改变其方向,其余的控制器都正常工作。

任何帮助将非常感激。 提前致谢。

从UIViewcontroller类的引用:“默认情况下,UIViewController类只在肖像模式下显示视图。为了支持额外的方向,你必须重写shouldAutorotateToInterfaceOrientation:方法并返回YES你的子类支持的任何方向如果你的视图的autoresizing属性被configuration正确的,这可能是你所要做的。“

由于你的模态视图inheritance自UIViewcontroller,所以你必须重写shouldAutorotateToInterfaceOrientation:在你的模态视图中。