UIAlertView and Landscape Mode

I bumped into a rather odd UI issue early last week – I was working on an application which runs entirely in landscape mode. However, when I displayed an alert view, it came up as follows:

Setting Landscape Mode

In my application, I had the following interface orientation setting inside the info.plist file:

Also, I rotated the main view controller as follows to set the orientation as needed:

  [self.view setCenter:CGPointMake(160.0f, 240.0f)];
  [self.view setTransform:CGAffineTransformMakeRotation(3.141592f / 2.0f)];
  self.view.bounds = CGRectMake(0, 0, 480, 320);

Even with the above, the device does not properly rotate the alert.

Show Alerts in Landscape Mode

To fix this, all you need to do is add the following line of code – I placed this in the applicationDidFinishLaunching method:

// Required so UIAlertView shows in the correct orientation in landscape mode
[application setStatusBarOrientation:
    UIInterfaceOrientationLandscapeRight animated:NO];

Much better.

  1. Hi. How do I make the image itself transform size? when I rotate phone image rotates but stay same size. Thanks!

    Rob.

    • Hi Rob, you’ll have to resize (or use an alternate image) when rotating to landscape mode, the device will not do this for you.

Comments are closed.