2

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 method:
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.

Nat
  • 12,032
  • 9
  • 56
  • 103

3 Answers3

2

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.

Community
  • 1
  • 1
Alessandro Vendruscolo
  • 14,493
  • 4
  • 32
  • 41
1

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

Nekto
  • 17,837
  • 1
  • 55
  • 65
0

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

Aman Agarwal
  • 727
  • 6
  • 15
  • 1
    That won't solve the problem because he wants to rotate screen after app is launched. – Nekto Sep 02 '11 at 07:42
  • Initial is only when you turn app on, my problem is i already turned it on and come back from different screen (1st paragraph of my question). Besides i need to set it to current device orientation not the one that i want. – Nat Sep 02 '11 at 07:44
  • @Nekto Not he but she ;) However seems there is no legal method for it like you've said. Thanks for help! – Nat Sep 02 '11 at 07:48