开发者

Device orientation - change in legal way (iOS 4.0+)

开发者 https://www.devze.com 2023-04-01 06:36 出处:网络
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,

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.

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 metho开发者_如何学编程d:
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

//3rd method:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

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.


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

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

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.


as I know there are no legal way. If I wrong, please, correct me somebody!


change the 'Initial interface orientation' in your project plist file

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号