Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I move a UIAlertView?

I've been moving an alert view slightly higher so i can fit a keyboard on screen as well. I just do this by grabbing the frame of the alert and changing the Y after i have already shown the alert so that the frame variables are legit. This works fine on the simulator, but when I do this on the hardware, the alert starts at the correct position but then almost immediately jumps down to it's original vertical center place. Is the UIAlertView position a fixed thing that isn't supposed to change per the usability guidelines or am i just doing something incorrectly?

Thanks!

like image 848
Skyler Avatar asked Jun 24 '09 18:06

Skyler


2 Answers

What OS are you trying this against? I got this to work on both the OS 3.0 Simulator and OS 3.0 Device:

UIAlertView * alert = [ [ UIAlertView alloc ] initWithTitle:@"Alert" message:@"Alert" 
                        delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil ];

alert.transform = CGAffineTransformTranslate( alert.transform, 0.0, 100.0 );

[ alert show ];

CGAffineTransformTranslate takes three arguments: the existing transform, an x transform, and a y transform. In the example I used, the alert view appeared 100 pixels higher than it normally would. Give this a try and see what happens.

Also, I'm pretty certain you can modify the frame before showing the alert as it likely sets up the alert's frame in init to be the center of the entire screen by default.

like image 79
CIFilter Avatar answered Sep 24 '22 18:09

CIFilter


Since iOS4 moving around UIAlertViews gets tricky. I've noticed that if you add a UITextField subview on the UIAlertView, on iOS4 the alert gets moved up so that the keyboard doesn't overlap it. This doesn't happen < iOS4.

Also I've noticed that the alert's frame isn't initialized even after show is called, so there is no easy programatic way of doing a relative CGAffineTransformation. The only solution would be to do conditional transforms based on the OS version.

To me this looks like threading over undocumented behavior of UIAlertViews that is subject to change at any time. I don't think Apple meant for us to be using the alerts for anything more than texts and buttons (even though their own applications break this rule).

I for one will start building my own custom alerts for this type of scenarios.

like image 31
Mihai Damian Avatar answered Sep 23 '22 18:09

Mihai Damian