11

My app is supposed to be landscape only, and I had no problem with this when building for iOS 6 and earlier. Now with iOS 7, It won't rotate at all.

In my app settings, I have it set to landscape left/right only. In my view controller, i'm using the following:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

I also used to use this, which is now deprecated:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return UIInterfaceOrientationIsLandscape(orientation);
}

The new one appears to be shouldAutorotate, but using this crashes my app. Any ideas on this would be appreciated, since my app is forced to portrait on my iPad and in the simulator. Thank you!

Deepesh
  • 8,065
  • 3
  • 28
  • 45
ultra
  • 329
  • 1
  • 4
  • 15
  • Can we have error message ? which you get in output window? – Jageen Sep 23 '13 at 12:58
  • For some reason I'm unable to get the exception. "po $r0" gives me "Couldn't materialize struct: couldn't read the value of register r0". – ultra Sep 23 '13 at 23:56
  • Same problem here, but without crash. I can't be force the app to run in Landscape mode only. It always autorotates. In iOS6 everyhing worked. – gdm Nov 04 '13 at 16:45
  • Did you solve your orientation problem? @ultra – Ganesh G Nov 29 '13 at 09:07
  • Yes, I answered this myself and forgot I had to go back and accept it. The answer I posted is working for me. – ultra Dec 23 '13 at 12:17

4 Answers4

12

This solves my problem. I'm not sure why I had issues before, but I must have missed trying this exact combination (also, info.plist should have the supported orientations set).

(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

(BOOL)shouldAutorotate {
    return YES;
}

edit: I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.

Artyom Neustroev
  • 8,627
  • 5
  • 33
  • 57
ultra
  • 329
  • 1
  • 4
  • 15
  • I couldn't get your answer to work but mine did after chatting on IRC with someone. It says I have to wait until tomorrow to accept my answer. – ultra Sep 24 '13 at 15:08
  • No, this does not solve the problem. http://stackoverflow.com/questions/20162216/how-to-make-universal-xcode-5-app-project-launch-in-landscape-orientation – openfrog Nov 23 '13 at 12:38
4

Include this method as well in your code:

- (BOOL)shouldAutorotate{
  if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight)
  {
    return YES;
  }
  else{
    return NO;
  }
}

Read this for more info. Here it is mentioned that we should override shouldAutorotate to suppress orientations.

If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.

Puneet Sharma
  • 9,369
  • 1
  • 27
  • 33
  • Is my use of supportedInterfaceOrientations correct? Now, it doesn't crash with shouldAutorotate (thank you), but it does when I use supportedInterfaceOrientations. I tried printing the exception, and I get "Couldn't materialize struct: couldn't read the value of register r0". – ultra Sep 23 '13 at 23:51
  • Yeah you are using that function correctly. Do one mor e thing. In your Project's BuildSettings, only support Landscape Left and Right modes. – Puneet Sharma Sep 24 '13 at 03:11
  • I have done that as well. Landscape left/right, no portrait. I'm still getting an exception, which I figured out how to display: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES. The answers I get to this problem tell me to do exactly what I'm already doing, so I'm at a loss here. I'm wondering if I'm having an XCode 5 issue. – ultra Sep 24 '13 at 10:40
  • Also, if I change my supported orientations to UIInterfaceOrientationMaskAll, I get no exception and no rotation. – ultra Sep 24 '13 at 10:45
  • Well according to the error, we have returned YES only when device is in Landscape mode. I do not understand the error then. Please clean/build your code and then check. Sometimes changes are not read by XCode. – Puneet Sharma Sep 24 '13 at 11:12
  • I actually found the solution and I'm posting the answer. – ultra Sep 24 '13 at 11:15
1

i don't know why, but this work for me on IOS 7

[[UIApplication sharedApplication] setStatusBarHidden:NO];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

[super willRotateToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0];
0

I may have having issues with the simulator, and doing a reset/restart and clean might have contributed to the fix.

This worked for me: (Simulator -> Reset Content and Settings...)

ShanghaiD
  • 1
  • 1