最終更新:2017-07-26 (水) 05:40:54 (2437d)
UIKit/キーボード
UITextFieldでリターンキーを押したときの動作
- 何もしてなければ何も起きない (閉じない)
- まずUITextFieldDelegate textFieldShouldReturn:が呼ばれる
- Asks the delegate if the text field should process the pressing of the return button.
UITextFieldDelegate textFieldShouldReturn:がreturn YESのとき
- IBActionでDid End On Exitがハンドルされているか?
- されている
- Editing Did Endが呼ばれる(キーボードが閉じる)
- されていない
- Editing Did Endは呼ばれない(キーボードが閉じない)
UITextFieldDelegate textFieldShouldReturn:がreturn NOのとき
- なにもおきない
メモ
- Did End On Exitをハンドルしない場合、UITextFieldDelegate textFieldShouldReturn内でresignFirstResponderを呼び出すとEditing Did Endが呼ばれる(キーボードが閉じる)
他のボタンを押すと閉じるようにする
[textField endEditing:YES];
通知
- When the system shows or hides the keyboard, it posts several keyboard notifications. These notifications contain information about the keyboard, including its size, which you can use for calculations that involve moving views. Registering for these notifications is the only way to get some types of information about the keyboard. The system delivers the following notifications for keyboard-related events:
- UIKeyboardWillShowNotification?
- UIKeyboardDidShowNotification?
- UIKeyboardWillHideNotification?
- UIKeyboardDidHideNotification?