Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Become first responder without animation

Is there a way for a UITextField to become first responder without the animation of the keyboard? That is, make it such that the keyboard just appears?

Basically, I'm pushing a second UIViewController over the UIViewController that has the UITextField, and when that second view controller gets popped off the stack, I want the UITextField to immediately have first responder status so that when the second view controller gets popped, the user never notices the text field wasn't first responder.

Right now I have it so that when it's popped, the keyboard animates up the screen, but I don't want that to be seen.

Any ideas?

like image 801
The Awesome Guy Avatar asked Aug 11 '12 19:08

The Awesome Guy


1 Answers

You can use a UIView animation like so

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.0];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

[textField becomeFirstResponder];  // <---- Only edit this line

[UIView commitAnimations];

This will cause the keyboard to suddenly appear.

You can do the same but with -resignFirstResponder

Swift ..

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0.0)
    UIView.setAnimationDelay(0.0)
    someTextView.resignFirstResponder()
    UIView.commitAnimations()
like image 71
David Skrundz Avatar answered Sep 22 '22 19:09

David Skrundz