Sunday, July 8, 2012

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 theapplicationDidFinishLaunching method:
// Required so UIAlertView shows in the correct orientation in landscape mode
[application setStatusBarOrientation:
UIInterfaceOrientationLandscapeRight animated:NO];

No comments:

Post a Comment