0

I seem to be having the opposite problem from this post:

Autorotate in iOS 6 has strange behaviour

When I submitted my paid app to Apple, XCode made me update to iOS 6 on my test devices. I used the GUI in XCode to set my app to display only in portrait mode on the iPhone and only in landscape mode on the iPad. This works great on my iOS 6 iPhone and iPad. In iOS 5, however, the iPad is allowing the app to rotate to portrait, displaying my buttons in a letterbox-like black area that shouldn't be there, and crashing repeatedly.

I am using a Navigation Controller and storyboards.

I know shouldAutorotateToInterfaceOrientation is deprecated in iOS 6, but figuring it should still be called in iOS 5, I tried this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(UIDeviceOrientationLandscapeLeft))||(UIDeviceOrientationIsLandscape(UIDeviceOrientationLandscapeRight))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(UIDeviceOrientationPortrait))||(UIDeviceOrientationIsLandscape(UIDeviceOrientationPortraitUpsideDown))) {
            return YES;
        }
        else return NO; }
    // Return YES for supported orientations
}

The above code seems to have done nothing. I am putting it in each of my view controllers; it seems I should really be putting it in my navigation controller, but because I set that up graphically, I'm not sure how to do that. Do I have to subclass my navigation controller and do everything in code? There must be a way to use the storyboard settings for this!

(Note: I am not using AutoLayout and apparently can't because of some older components I am including my software that just plain don't like it.)

What might be causing this? I'd like to fix it before too many people buy the app and complain! Thanks in advance...

Community
  • 1
  • 1
Jeanne
  • 87
  • 1
  • 8

1 Answers1

2

I think the code should be like this, where you use "interfaceOrientation", parameter passed into the method for your comparison:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
        return YES;
    }
    else return NO;
}
else
{
    if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
        return YES;
    }
    else return NO; }
Bek
  • 2,206
  • 20
  • 35
  • Thank you, @Bek! In the second half, I think you meant if landscape, NO, and else YES... Oddly, it doesn't seem to work for PortraitUpsideDown if I try to invoke UIDeviceOrientationIsPortrait, but using IsLandscape and reversing the logic does work. – Jeanne Nov 01 '12 at 17:51
  • Sorry - I just copied what you had and didn't bother flipping the logic. Glad it worked for you! For the upside down, there doesn't appear to be a macro function like UIDeviceOrientationIsPortrait. I usually just do: return interfaceOrientation != UIDeviceOrientationPortraitUpsideDown to allow all rotations except upside down, instead of doing all the macros. – Bek Nov 01 '12 at 18:13