Rotating a UIAlertView

Peter Sarnowski picture Peter Sarnowski · Jul 28, 2011 · Viewed 7k times · Source

I've created a custom UIAlertView (by subclassing it and messing around with its show function) that has some custom subviews and is of non-standard size.

It works ok when I create and display it, however, when the device is rotated, the alert rotates and then returns to its default size.

Any ideas what functions to override - or should I tweak the UIViewController?

thanks, Peter

Answer

Nils Munch picture Nils Munch · Jul 28, 2011

Not sure if force rotating the UIAlertView fits the Apple GUI guidelines, but you can rotate it by defining the status bar (status bar and UIAlertView sticks together)

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
application.statusBarOrientation = UIInterfaceOrientationLandscapeLeft;

But UIAlertView is a UIView just like many others, so try this :

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