代码之家  ›  专栏  ›  技术社区  ›  SolidSnake4444

iPad “dismiss keyboard” button (lower right), how do I detect when this occurs? What function tells me it was pressed?

  •  21
  • SolidSnake4444  · 技术社区  · 15 年前

    I have an ipad app that when you are in landscape view, the view will move up when the keyboard is brought in. When you press done on the keyboard, textFieldShouldReturn and textFieldShouldEndEditing are called in which case, I move the view down in shouldEndEditing.

    谢谢!

    3 回复  |  直到 12 年前
        1
  •  26
  •   Sharjeel Aziz    15 年前

    你可以听键盘隐藏 ui键盘将隐藏通知 通知。

    这里是示例代码 http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html

        2
  •  12
  •   pablasso Jordan    12 年前

    按下“下键盘”按钮时,textfield委托方法:

    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    

    不会被叫来的。

    当按下“下键盘”或“返回按钮”时:

    -(void)textFieldDidEndEditing:(UITextField *)textField
    

    将被调用。

    我使用变量 NSString *lowerKeyboardButtonPressed 最初设置为 @"" 我设置 @"N" textfieldShouldReturn 方法…然后在 textFieldDidEndEditing 方法我检查它是否设置为 @“N” …然后我知道是按了回车键还是下键盘键。我的最后一行 文本字段结束编辑 method sets the variable back to @ .

        3
  •  2
  •   EdChum Arthur G    13 年前

    如果您按下键盘解除按钮并连接了硬件键盘,则 willHide will only be called if you don't have an input accessory view. At which point you need to adjust in the willShow 以及(这将在 UIKeyboardFrameBeginUserInfoKey UIKeyboardFrameEndUserInfoKey 钥匙。