开发者

UICatalog and Keyboard Events

The latest version of Apple's UICatalog example application includes zero code in the TextFieldController for handling keyboard show/hide events, and yet the table view still slides up and down beautifully with the keyboard.

Does anyone know what the new trick is? Are there settings in the XIB that allowed them to forgo registering for the notifications or using TextField delegate methods?

The TextViewController still uses keyboard notifications to deal with view sliding, so I'm really c开发者_JS百科onfused as to why this isn't included for TextFields anymore.

Thoughts?


You can close the keyboard, if it's open by calling:

[sender resignFirstResponder];

Not sure about opening the keyboard however.


The trick is hidden within calling becomeFirstResponder on a UITextField that is in a scrollable view. Apparently, whenever calling [textField becomeFirstResponder], iOS automatically scrolls the parent view until said textField is visible.

This behavior can actually be undesirable in some cases, as it will not usually scroll to the same location that the UIScrollView method scrollRectToVisible:animated: would if you were to try to do things that way.

Thanks for your thoughts everyone!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜