Question

I have an iPad application where I'm moving the application's frame "up" every time the soft keyboard is shown.

[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = CGRectMake(0, 150, 1024, 768);

The clincher is that on some devices this goes the correct way, but on other's it goes the opposite direction than I want it to. It doesn't seem to be hardware specific or even software specific. I have tried it on 4 iPads (two ipad1, two ipad3 and one ipad2) all with ios 5.1 (9B176). Is there a way to know if this is going to happen on a device so that I can combat this with logic?

Also, It seems that devices that are going to do this do it and stay that way as well (and vice-versa). Once it happens, it always happens or not regardless of software update, device restart, app removal, or IPA vs ran-from-xcode.

Was it helpful?

Solution

You're setting the view's frame - but the frame coordinates need to be relative to the view's superview (in this case the keyWindow), not itself. Since the window is never rotated, your frame coordinates will be interpreted differently, depending on the device's current orientation.

You could do the following to convert your frame coordinates to ones suitable for the keyWindow:

CGRect newFrame = [self.view convertRect:CGRectMake(0, 150, 1024, 768) toView:[UIApplication sharedApplication].keyWindow];
[UIApplication sharedApplication].keyWindow.rootViewController.view.frame = newFrame;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top