两个 UITextFields - 将第一个键盘滑出,然后滑入

发布于 2024-09-10 08:34:30 字数 401 浏览 5 评论 0原文

所以在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剪不断理还乱 2024-09-17 08:34:30

你有理由这样做吗?这显然会增加用户输入信息所需的时间,我知道这会让我烦恼。

但如果你确实想要这种效果,那么我会看看这样的东西:

[dateTextField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:timeDelay];

其中 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:

[dateTextField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:timeDelay];

Where timeDelay is the amount of time it takes to dismiss the first keyboard.

佞臣 2024-09-17 08:34:30

您可以注册以观察这些通知:UIKeyboardWillShowNotificationUIKeyboardWillHideNotification。这会让你跟踪正在发生的事情,但它很容易变得相当复杂,所以汤姆·欧文的建议可能更容易使用。

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.

孤君无依 2024-09-17 08:34:30

要获取有关键盘隐藏和显示的通知,请查看

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:)
    name:UIKeyboardDidHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) 
    name:UIKeyboardDidShowNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
    name:UIKeyboardWillHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:[self view].window];

并添加适当的方法,例如

-(void)keyboardWillShow:(NSNotification*)notif
-(void)keyboardWillHide:(NSNotification*)notif
-(void)keyboardDidShow:(NSNotification*)notif
-(void)keyboardDidHide:(NSNotification*)notif

然后您可以按照您喜欢的方式连接动画。

确保 NSLog() 所有这些,它们并不总是在您期望的时候被调用(臭名昭著的是当您从一个字段转到另一个字段时,您会立即收到 willhide 和 willshow )

To get notifications on keyboard hiding and showing, have a look at

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:)
    name:UIKeyboardDidHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) 
    name:UIKeyboardDidShowNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
    name:UIKeyboardWillHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:[self view].window];

and add appropriate methods like

-(void)keyboardWillShow:(NSNotification*)notif
-(void)keyboardWillHide:(NSNotification*)notif
-(void)keyboardDidShow:(NSNotification*)notif
-(void)keyboardDidHide:(NSNotification*)notif

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文