Swiftpack.co - Package - tommy10344/KeyboardAvoider

KeyboardAvoider

KeyboardAvoider is the utility class for prevent covering TextField by software keyboard.

Usage

  • Initialize KeyboardAvoider class with scrollView.
self.keyboardAvoider = KeyboardAvoider(scrollView: scrollView)
  • Set UITextFieldDelegate to textField and call textFieldDidBeginEditing() in UITextFieldDelegate's textFieldDidBeginEditing()
func textFieldDidBeginEditing(_ textField: UITextField) {
    keyboardAvoider.textFieldDidBeginEditing(textField)
}
  • Call beginObservingKeyboardEvent() in viewWillAppear()
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    keyboardAvoider.beginObservingKeyboardEvent()
}
  • Call endObservingKeyboardEvent() in viewWillDisappear()
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    keyboardAvoider.endObservingKeyboardEvent()
}

Github

link
Stars: 1

Dependencies

Used By

Total: 0