Keyboard Animation Issues When Calling becomeFirstResponder within a Modal View Controller
- by LucasTizma
I've been having some issues with calling -becomeFirstResponder on a UITextField contained with a view controller that is presented modally. I call this method in the modal view controller's -viewDidLoad method so that the keyboard is immediately displayed. What I expected is for both the keyboard and the modal view controller to animate from up the bottom of the screen at the same time. However, what I'm observing is the following:
There is a ~0.2 second UI lag between clicking the button that calls the -presentModalViewController:animated: method on the parent view controller and when the child view controller begins to animate modally.
The keyboard is immediately presented with absolutely no animation about half-way through the modal view controller's animation.
Once the modal view controller's animation is complete, everything else seems to operate smoothly. Dismissing the modal view controller results in it being smoothly animated off screen (along with the keyboard, coincidentally).
It's as if the keyboard's animation and the modal view controller's animation are both competing for some lower-level Core Animation resource at the same time, but I don't see why this should be happening. What further seems to corroborate this hunch is if I don't ask the UITextField to become the first responder (i.e., if I don't ask the keyboard to present itself), then there is absolutely no UI lag, and the modal view controller animates instantly.
Interestingly, if I do something like [self.textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0001]; then the animation of the keyboard happens nearly at the same time as the modal view controller's animation -- it's extremely difficult to tell that they aren't both being animated at the exact same time. Furthermore, there's no more UI lag.
Has anyone experienced anything similar to this?