two UITextFields - slide first Keyboard out and next in

不想你离开。 提交于 2019-12-25 04:53:20

问题


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!


回答1:


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.




回答2:


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.




回答3:


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)



来源:https://stackoverflow.com/questions/3275635/two-uitextfields-slide-first-keyboard-out-and-next-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!