Set of protocols that simplifies work with adding extra space when keyboard is shown, hidden or changed.
Features:
- Correctly works with keyboard frame changes (e.g. keyboard height changes like emojii → normal keyboard).
- TabBar & ToolBar support for UITableView example (at other examples you receive incorrect insets).
- Dynamic animation duration (not hard-coded).
- Protocol-oriented approach that could be easily modified for you purposes.
Basic usage example in view controller that contains some scroll view.
class SomeViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
addKeyboardFrameChangesObserver()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
removeKeyboardFrameChangesObserver()
}
}
extension SomeViewController: ModifableInsetsOnKeyboardFrameChanges {
var scrollViewToModify: UIScrollView { return scrollView }
}
Protocol KeyboardChangeFrameObserver
will fire event each time keyboard frame was changed (including showing, hiding, frame changing).
- Call
addKeyboardFrameChangesObserver()
atviewWillAppear()
or similar method. - Call
removeKeyboardFrameChangesObserver()
atviewWillDisappear()
or similar method.
ModifableInsetsOnKeyboardFrameChanges
protocol adds UIScrollView
support to core protocol. It changes scroll view's insets when keyboard frame is changed.
Your class needs to set scroll view, one's insets will be increased / decreased on keyboard frame changes.
var scrollViewToModify: UIScrollView { get }