开发者

UICatalog and Keyboard Events

开发者 https://www.devze.com 2022-12-22 19:20 出处:网络
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 beaut

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

精彩评论

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