两个 UITextFields - 将第一个键盘滑出,然后滑入
所以在我的 viewdidload 中
[nameTextField becomeFirstResponder]
,在单击按钮后,我想滑出此文本字段的键盘,然后将另一个文本字段的另一个键盘滑入。
我想过,
[nameTextField resignFirstResponder];
[dateTextField becomeFirstResponder];
但另一个键盘立即出现。
注释 [dateTextField comeFirstResponder];
,效果是我的 nameTextField 键盘按我想要的方式滑出。
有什么想法如何做到这一点?
谢谢!
so in my viewdidload i got something like
[nameTextField becomeFirstResponder]
now after a button gets klicked, i want to slide out the keyboard of this textfield, and slide another keyboard of another textfield in.
i thought about
[nameTextField resignFirstResponder];
[dateTextField becomeFirstResponder];
but the other keyboard shows up immediately.
commenting the [dateTextField becomeFirstResponder];
out, effects that my nameTextField keyboard slides out as i wanted.
any ideas how to do this?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你有理由这样做吗?这显然会增加用户输入信息所需的时间,我知道这会让我烦恼。
但如果你确实想要这种效果,那么我会看看这样的东西:
其中 timeDelay 是关闭第一个键盘所需的时间。
Is there a reason why you want to do this? It will obviously increase the time it takes for a user to enter information, which I know would bug me.
But if you do really want this effect, then I would look at something like this:
Where
timeDelay
is the amount of time it takes to dismiss the first keyboard.您可以注册以观察这些通知:
UIKeyboardWillShowNotification
、UIKeyboardWillHideNotification
。这会让你跟踪正在发生的事情,但它很容易变得相当复杂,所以汤姆·欧文的建议可能更容易使用。You can register to observe these notifications:
UIKeyboardWillShowNotification
,UIKeyboardWillHideNotification
. That will let you keep track of what is going on, but it can easily get pretty complicated so Tom Irving's suggestion might be easier to work with.要获取有关键盘隐藏和显示的通知,请查看
并添加适当的方法,例如
然后您可以按照您喜欢的方式连接动画。
确保 NSLog() 所有这些,它们并不总是在您期望的时候被调用(臭名昭著的是当您从一个字段转到另一个字段时,您会立即收到 willhide 和 willshow )
To get notifications on keyboard hiding and showing, have a look at
and add appropriate methods like
Then you can connect the animations any way you like.
Be sure to NSLog() all of them, they are not always called when you would expect them (the notorious one being when you go from one field to another, and you receive the willhide and willshow immediately)