Rotating a UIAlertView
Asked Answered
N

1

7

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

Nebulous answered 28/7, 2011 at 13:6 Comment(1)
Okay, I found out that resetting the bounds rectangle in setNeedsDisplay works to reset the size... but now I have a pretty bizarre chain of events whenever I rotate the device: 1) The UIAlertView is displayed properly, 2) The UIAlertView shrinks back to its default size 3) The UIAlertView rotates 4) The UIAlertView returns to desired size Any ideas how to prevent the shrinking during animation?Nebulous
S
4

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];
}
Streptokinase answered 28/7, 2011 at 13:10 Comment(2)
Seems like my question wasn't clear enough... My UIAlertView DOES rotate on its own, when the device orientation changes. The problem is that it also changes size.Nebulous
I am also facing same problem.Pieter

© 2022 - 2024 — McMap. All rights reserved.