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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With