iOS engineer who likes clean, simple designs and sans-serif.

Loading

iOS Rotation / Changing Orientation

If you want your app to do something when you change the orientation from portrait to landscape, here’s a method you can use for when the rotation completes:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    // Insert code here
}

However, you may notice that it doesn’t work in Portrait Upside Down mode. “By default, view controllers on devices that use the iPad idiom support all four orientations. On devices that use the iPhone idiom, all interface orientations but upside-down portrait are supported.”

To fix this, you need to enable it in the project settings and also override the default supported interface orientations like this:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskLandscapeRight;
}

Still not working for you? Well for more options, you can check out this diagram from the Objective C documentation:
iOSInterfaceRotation

Leave a Comment