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

时间:2011-09-02 07:36:29

标签: iphone objective-c ios orientation

我的应用程序有导航栏,第一个屏幕返回YES到方向,第二个屏幕根据用户在第一个屏幕中选择的内容设置为某个方向。从第二个屏幕返回第一个屏幕后,如果用户手持设备,但界面处于横向状态,则第一个屏幕设置为横向。这是因为

(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];

第1次表演很奇怪,旋转所有情况除了从界面方向返回=风景和设备方向=风景(这是一个错误,他旋转到风景) 第2次检查界面,就像名字告诉的那样,并且对我的问题不起作用 据我所知,第三名是私人的,Apple拒绝使用此应用程序。

3 个答案:

答案 0 :(得分:2)

看看这个thread。 基本上,没有办法强制设备方向让Apple批准您的申请。

很快,该方法存在,但是UIDevice类的未记录方法。

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

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

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

另外,有人说您可以使用performSelector间接调用这些方法来绕过Apple的静态代码分析,因为您可以在评论here中阅读。

答案 1 :(得分:1)

据我所知,没有合法途径。如果我错了,请告诉我某人!

答案 2 :(得分:0)

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