I have an app that has a text field on the lower half of the view. This means that when I go to type in the text field the keyboard covers the textfield.
How would I go about moving the view upwards while typing so I can see what i'm typing and then moving it back down to its original place when the keyboard disappears?
I've looked everywhere but all the solutions appear to be in Obj-C which I can't quite convert just yet.
Any help would be greatly appreciated.
@Boris's solution is VERY good but the view can sometimes be corrupted.
For the perfect alignment, use the below code
Functions:
And,
its 100% Perfect Answer For all Guy's Update Tableview Height when open Keyboard
For Black Screen Error ( Swift 4 & 4.2 ) .
I fixed the black screen problem. In the verified solution The keyboard height changes after tapping and this is causing black screen.
Have to use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey
Here is a solution, without handling the switch from one textField to another:
To solve this, replace the two functions
keyboardWillShow/Hide
with these:EDIT FOR SWIFT 3.0:
EDIT FOR SWIFT 4.0:
EDIT FOR SWIFT 4.2:
Swift 4:
I was having an issue with the most accepted answer, in which hiding the keyboard did not return the view all the way to the bottom of the page (only partially). This worked for me (+updated for Swift 4).