Monday, December 22, 2008

UIAlertView & Landscape Mode

I've been wrestling with something today. I think this is new incorrect behavior. I could be wrong about it being new, but it definitely seems incorrect.

When your application is in landscape mode, and you show an UIAlertView, that alert view gets shown in portrait mode, meaning it's sideways to the user. Obviously, that makes it awkward and a little hard to read.

I tried many things to get it to work right, without much success. If I changed the view's transformation before the view was shown to the user, it got overwritten and put in the incorrect orientation anyway. My attempts to subclass UIAlertView were unsuccessful in fixing the problem. The best I could do was to change the view's orientation right after it's displayed to the user, animating the change to make it less jarring.

In order to do that, you have to implement the delegate method didPresentAlertView: on your view's delegate. If you're not using a delegate, simply pass self and implement this method in your controller class where you create and show the alert.

- (void)didPresentAlertView:(UIAlertView *)alertView
{
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationDuration:0.1];
alertView.transform = CGAffineTransformRotate(alertView.transform, degreesToRadian(90));
[UIView commitAnimations];
}


I have submitted this as a bug to Apple, and I have to assume I'm not the only one who has, but in the meantime, this is the best I've been able to come up with. If anyone has a better solution, I'd love to hear it. I'm not looking forward to letting my client see their app like this.

No comments:

Post a Comment