Simple keyboard listener in Swift
I’ve just published a small sample project to provide a reusable keyboard listener that will ensure that an input field won’t be hidden under the keyboard.
This require to embed your input fields inside a UIScrollView object.
If you are using a UITableView, this is already the case.
You need to implement a getter closure that will return the currently active input field.
How can you use this class?
Just import the framework:
import SGiT_KeyboardListener
Then your controller shall declare a variable to keep reference to the listener:
var keyboardListener: KeyboardListener?
Creat the listener when the view is loaded:
override public func viewDidLoad()
{
super.viewDidLoad()
keyboardListener = KeyboardListener(scrollView: tableView, controller: self) {
return self.activeField
}
// to be continued...
}
And that’s all.
More information in the repository Swift-SGiTKeyboardListener
Feedback is welcome!