Can I move a UIAlertView?

I am moving the warning view a little higher, so I can put the keyboard on the screen. I just do this by grabbing the warning frame and changing Y after I have already shown the warning so that the frame variables are legal. This works fine on a simulator, but when I do it on hardware, the warning starts in the correct position, but then it goes almost immediately to the original vertical center location. Is the UIAlertView position fixed, which should not be changed according to the usability guidelines, or am I just doing something wrong?

Thanks!

+6
iphone uialertview
source share
3 answers

What OS are you trying to do this with? I got this to work with both OS 3.0 Simulator and OS 3.0:

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, the x transform, and the y transform. In the example I used, the warning view appeared 100 pixels higher than usual. Try it and see what happens.

In addition, I am pretty sure that you can change the frame before showing a warning, as it seems to set the notification frame to init by default for the center of the entire screen.

+22
source share

Since iOS4 navigating UIAlertViews is getting complicated. I noticed that if you add a subview UITextField to the UIAlertView, on iOS4 the warning will be moved up so that the keyboard does not overlap it. This does not happen <iOS4.

I also noticed that the warning frame is not initialized even after calling show, so there is no easy programmatic way to do relative CGAffineTransformation. The only solution would be to make conditional conversions based on the OS version.

For me, it looks like a flood of undocumented UIAlertViews behavior that can be changed at any time. I do not think that Apple meant that we used warnings for anything more than texts and buttons (even if their own applications violate this rule).

I for one will start to create their own custom alerts for this type of scenario.

+2
source share

Is not a warning meaning modal - that is, you will not be doing any other user input at all while the warning is active? If so, why do you need keyboard visibility?

+1
source share

All Articles