简化iOS的键盘处理:KeyboardController

jopen 11年前

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.open-open.com/lib/view/home/1390787994398