手动设置界面方向

有没有简单的方法来手动设置接口的方向? 我需要将界面设置为纵向,即使在装载期间设备方向可能处于横向。 有点想远离CGAffineTransforms。

我知道的一种方法对我很有用(而且有点破解,可以在改变到你想要的方向之前显示一个方向):

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIApplication* application = [UIApplication sharedApplication]; if (application.statusBarOrientation != UIInterfaceOrientationPortrait) { UIViewController *c = [[UIViewController alloc]init]; [self presentModalViewController:c animated:NO]; [self dismissModalViewControllerAnimated:NO]; [c release]; } } 

首先,设置您的应用程序和视图只支持肖像,然后使用从我的重构库, es_ios_utils采取这种类别的方法:

 @interface UIViewController(ESUtils) // Forces without using a private api. -(void)forcePortrait; @end @implementation UIViewController(ESUtils) -(void)forcePortrait { //force portrait orientation without private methods. UIViewController *c = [[UIViewController alloc] init]; [self presentModalViewController:c animated:NO]; [self dismissModalViewControllerAnimated:NO]; [c release]; } @end 

在框架完成之前被解散的视图将不会显示。

覆盖这个来控制方向,直到加载…

 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation