设备方向 – 以合法方式更改(iOS 4.0+)

我的应用程序有导航栏,第一个屏幕返回YES为方向,第二个设置为基于用户在第一个屏幕中select的某个方向。 从第二个画面回到第一个画面后,如果用户手持纵向设备而界面处于横向画面,则第一个画面设置为横向。 这是因为

(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation 

仅在更改设备方向后才被调用。

我想检查什么是设备方向atm和设置界面的方向。 尝试:

 //1st method: UIViewController *rotateTheScreen = [[UIViewController alloc]init]; [self presentModalViewController:rotateTheScreen animated:NO]; [self dismissModalViewControllerAnimated:NO]; [rotateTheScreen release]; //2nd method: UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; //3rd method: UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; 

第一个是奇怪的,除了从界面方向=横向和设备方向=横向(这里是一个错误,他旋转到横向)回来的所有情况下,第二个检查界面,如名称告诉,并没有工作我的问题第三据我所知是私人的,苹果拒绝使用这个应用程序。

看看这个线程 。 基本上,没有办法强制设备定位, 获得苹果公司的批准。

这个方法不久就存在,但是它是UIDevice类的一个没有logging的方法。

 [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight animated:YES]; 

这给编译器警告,你可以摆脱一个类别。

 @interface UIDevice (MyAwesomeMethodsThatAppleWillNeverAllowMeToUse) -(void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated; -(void)setOrientation:(UIInterfaceOrientation)orientation; @end 

此外,有人说,你可以使用performSelector来间接地调用这些方法来绕过苹果的静态代码分析,你可以在这里阅读评论。

据我所知,没有合法的途径。 如果我错了,请纠正我的错误!

更改项目plist文件中的“初始界面方向”