UICatalog 和键盘事件
Apple 的 UICatalog 示例应用程序 的最新版本包括零代码TextFieldController 用于处理键盘显示/隐藏事件,但表格视图仍然可以随着键盘完美地上下滑动。
有谁知道新的技巧是什么吗? XIB 中是否有设置允许他们放弃注册通知或使用 TextField 委托方法?
TextViewController 仍然使用键盘通知来处理视图滑动,所以我真的很困惑为什么 TextFields 不再包含它。
想法?
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 confused as to why this isn't included for TextFields anymore.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果键盘已打开,您可以通过调用以下命令关闭键盘:
[sender resignFirstResponder];
但是不确定是否打开键盘。
You can close the keyboard, if it's open by calling:
[sender resignFirstResponder];
Not sure about opening the keyboard however.
这个技巧隐藏在对可滚动视图中的
UITextField
调用becomeFirstResponder
中。显然,每当调用[textFieldBecomeFirstResponder]
时,iOS 都会自动滚动父视图,直到所述textField
可见。在某些情况下,这种行为实际上是不受欢迎的,因为如果您尝试这样做,它通常不会滚动到
UIScrollView
方法scrollRectToVisible:animated:
会滚动到的位置事情就是这样。谢谢大家的想法!
The trick is hidden within calling
becomeFirstResponder
on aUITextField
that is in a scrollable view. Apparently, whenever calling[textField becomeFirstResponder]
, iOS automatically scrolls the parent view until saidtextField
is visible.This behavior can actually be undesirable in some cases, as it will not usually scroll to the same location that the
UIScrollView
methodscrollRectToVisible:animated:
would if you were to try to do things that way.Thanks for your thoughts everyone!