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.



8 comments:

Scott Squires said...

I'm not having that problem. Is your status bar in the landscape orientation as well?

I also use UIActionSheetStyle without issue in landscape mode.

Jeff LaMarche said...

I never had the problem before the 2.2 sdk, which is why I think it's 2.0. I'll post some more info - maybe somebody can see something I've overlooked (probably something stupid if it is)...

Wayne said...

This issue still exists in 2.2.

Khalil said...

Just add this and it works fine :

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

Gary said...

This column is deeply nice for me as Generic Viagra since I love every single thing that is somehow related to landscapes.I hope my life is time enough to see many different kind of landscapes all over the world.

JeansPilot said...

JeansPilot offers the chance to buy a large variety of men’s and women’s jeans clothing from the world famous Italian Brands.
Online jeans clothing store looks for original fashion clothing sales and clearances of worldwide known designers. We participate in fashion auctions to get the lowest possible price for Top quality Clothes, Shoes and Accessories.
Buy Jeans

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels