This class scrolls the screen upwards when the virtual keyboard is shown so that it doesn't cover the actual text field.
There are many solutions to the annoying problem of having the virtual keyboard cover the currently focused UITextField. I've seen some use a good universal implementation like IQKeyboardManager BUT they are not updated for use with or without Autolayout or other issues. This solution is fairly simple and adds a UIScrollView between your UIView and it's superview automatically. Sometimes simple is best. It works for views that use Autolayout constraints or just plain resizing masks.
- Create an instance of KeyboardHelper.
let keyboardHelper = KeyboardHelper()
- Add it to the superview of the UITextField or the view you wish to be scrolled up.
keyboardHelper.addTo(view: content)
Optionally: add your code in for the keyboard events
onKeyboardWillBeShown
onKeyboardWillBeResized
onKeyboardWillBeHidden
See the demo project KeyboardDemo for an example. or try it on Appetize
When you attach it to a view it adds a UIScrollView as it's superview that uses the view as it's content.
It also adds a gesture recognizer that resigns the current first responder when tapped.
For any bugs, changes or requests please contact me by email: [email protected] or check out my site www.wfff.info
Thanks.