首页 > iphone > 强制重新计算键盘高度

强制重新计算键盘高度 (Force recalculation of keyboard height)

2013-04-20 iphonexcode4.6

问题

这个问题与我在这里的另一个问题有关,但这是我所面临问题的一​​个更集中的部分。

我有5个文本字段,我想移动(滚动)视图,因此键盘不会隐藏活动字段。我已经按照标准Apple推荐的方法实现了keyboardWillShow:文本字段委托方法,并且它适用于我第一次点击任何文本字段时。

但是,我已使用“下一步”按钮替换了键盘上的“返回”按钮。按下时,焦点会跳到下一个文本字段。并且由于进程中的键盘既没有隐藏也没有再次显示,我的keyboardWillShow:方法没有被调用 - 我从NSLogs中看到了这个,我放在那里没有出现在控制台中。

我单击下一步时如何强制重新计算键盘高度的任何想法?我理解的一件事是,为了获得键盘高度(我不想使用硬编码高度),我需要将计算保存在以通知作为参数的方法中。

任何想法或建议?

解决方法

当然keyboardWillShow没有按照你说的那样调用。

只需使用textField:didEndEditing或更好textField:shouldBeginEditing的下一个文本字段,并使用相同的逻辑。

要解决键盘高度和位置问题,请使用所需数据保留变量,并使用常用通知挂钩使其保持最新。

问题

This question is linked to my other question here, but this is a more focused part of the problem I'm facing.

I have 5 text fields, and I want to move the (scroll) view so the keyboard doesn't hide the active field. I have implemented keyboardWillShow: text field delegate method as per standard Apple recommended approach, and it works well for when I tap on any text field the first time.

However, I have replaced the Return button on the keyboard with Next button. When it is pressed, the focus jumps onto the next text field. And since the keyboard in the process is neither hidden nor shown again, my keyboardWillShow: method is not called - I see this from the NSLogs I've placed there which are not appearing in console.

Any ideas how I can force the re-calculation of keyboard height when I click Next? One thing I understand is that in order to get the keyboard height (I don't want to use hard-coded heights), I need to keep the calculations in a methods that takes aNotification as an argument.

Any ideas or suggestions?

解决方法

Of course keyboardWillShow is not called as you stated correctly.

Just use textField:didEndEditing, or better textField:shouldBeginEditing of the next text field, and use the same logic.

To solve the keyboard height and location problem, keep a variable with the data you need and use the usual notification hooks to keep it up to date.

相似信息