成为没有动画的第一响应者 [英] Become first responder without animation

查看:105
本文介绍了成为没有动画的第一响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 UITextField 成为没有键盘动画的第一响应者?也就是说,让键盘出现?

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?

基本上,我推了第二个 UIViewController UIViewController UITextField ,当第二个视图控制器弹出堆栈时,我想要 UITextField 立即拥有第一响应者状态,以便在弹出第二个视图控制器时,用户从不会注意到文本字段不是第一响应者。

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.

有什么想法吗?

推荐答案

你可以像这样使用UIView动画

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.

您可以这样做,但 -resignFirstResponder

Swift ..

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0.0)
    UIView.setAnimationDelay(0.0)
    someTextView.resignFirstResponder()
    UIView.commitAnimations()

这篇关于成为没有动画的第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆