Howto set up shouldAutorotateToInterfaceOrientation

Now here I have a bone to pick with many iOS Developers!

Please set up your UIViewController’s

"- (BOOL)shouldAutorotateToInterfaceOrientation:"

correctly, so you support both your Orientation and its UpsideDown-Version. Yes, it’s fine to just support Portrait or Landscape mode, but please support both directions!

You see UIInterfaceOrientation has 4 directions:

typedef enum {
UIInterfaceOrientationPortrait          = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;

Now I’m fine if you just want to support Portrait or Landscape and don’t want to resize everything between the two form-factors. Still for each direction there exist two entrys in this enum, and if you just do

(interfaceOrientation == UIDeviceOrientationPortrait)

you are just testing for one direction, not its variant turned around 180°. So please do the following instead:


so finally your “shouldAutorotateToInterfaceOrientation” could look like this if you plan to show your App in Portrait Mode:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);

This is not adding any extra work!

UIViews get rotated by 180° by UIKit, so allowing the user to turn the iPhone or iPad around can be achieved by changing one simple line per ViewController! There’s really no extra work in setting up all the frames because the formfactor stays the same, everything just turned upside down.

I understand this is completely obvious for all seasoned iOS Developers and was probably covered in depth on many times. Yet it still seems to happen in many Apps that I downloaded, so I thought I’d mention it.

One Response to “Howto set up shouldAutorotateToInterfaceOrientation”

  1. Thanks – was helpful for a noob! 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: