簡化iOS的鍵盤處理:KeyboardController

jopen 10年前發布 | 16K 次閱讀 iOS開發 移動開發 KeyboardController

KeyboardController用于簡化iOS的鍵盤處理。

用法:

To use KeyboardController, simply initialize it with an array of UITextField objects.

id textFields = @[_textField1, _textField2, 
                _textField3, _textField4, _textField5];
self.keyboardController = [KeyboardController controllerWithTextFields:textFields];

KeyboardController, depending on a returnKeyType property of an UITextField instance, will:

  • UIReturnKeyNext - move to next text field
  • UIReturnKeyDone - close keyboard

You can interact with KeyboardController directly via the following methods:

- (void)moveToNextTextField;
- (void)moveToPreviousTextField;
- (void)closeKeyboard;

KeyboardControllerDelegate

You could also take advantage of delegation methods:

- (void)controllerDidHideKeyboard:(KeyboardController *)controller;
- (void)controllerDidShowKeyboard:(KeyboardController *)controller;
- (void)controllerWillHideKeyboard:(KeyboardController *)controller;
- (void)controllerWillShowKeyboard:(KeyboardController *)controller;

by setting a delegate property of a KeyboardController:

self.keyboardController.delegate = self; 

UITextFieldDelegate

There is also an option of setting a textFieldDelegate property of all textFields that are under control of KeyboardController:

self.keyboardController.textFieldDelegate = self; 

This could be particulary useful if you would like to add individual behaviour to UITextFields objects.

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (textField == self.textField4) [self _moveViewByY:-50];
    if (textField == self.textField5) [self _moveViewByY:-200];
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.textField4) [self _moveViewByY:50];
    if (textField == self.textField5) [self _moveViewByY:200];
}

項目主頁:http://www.baiduhome.net/lib/view/home/1390787994398

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!