设备方向 - 以合法方式更改(iOS 4.0+) [英] Device orientation - change in legal way (iOS 4.0+)

查看:120
本文介绍了设备方向 - 以合法方式更改(iOS 4.0+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My app has navigation bar, where 1st screen returns YES to orientation, the second one is set to some orientation basing on what user choose in 1st screen. After going back to 1st screen from 2nd one, if user had device in hand in portrait but interface was in landscape, 1st screen is set to landscape. This happens because of

(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation 

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

Is called only after changing device orientation.

我想检查什么是设备方向atm并设置界面这个方向。
尝试:

I want to check what is device orientation atm and set interface orientation to this one. Tried:

//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个表现很奇怪,除了从界面方向返回所有情况外还旋转=横向和设备方向=横向(这是一个错误,他转向横向)
第二次检查界面,就像名字告诉的那样,并且对我的问题不起作用
就我听说是私有而且Apple拒绝使用这个应用程序。

1st is acting strange, rotates all cases besides coming back from interface orientation = landscape and device orientation = landscape (here is a bug, he rotates to landscape) 2nd checks interface, like the name tells, and tho doesnt work for my problem 3rd as far as i heard is private and Apple rejects apps using this.

推荐答案

看看这个螺纹
基本上,没有办法强制设备导向让Apple批准你的申请。

Take a look at this thread. Basically, there's no way to force a device orientation and get your application approved by Apple.

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

Shortly, the method exists but is an undocumented method of the UIDevice class.

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

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

This gives a compiler warning that you can get rid of with a category.

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

此外,有人说你可以使用<$ c间接调用这些方法$ c> performSelector 以了解Apple的静态代码分析,您可以在评论中阅读这里

Also, some say that you can call these methods indirectly using performSelector to get around Apple's static code analysis, as you can read in the comments here.

这篇关于设备方向 - 以合法方式更改(iOS 4.0+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆