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.
For Swift 3
this video tutorial is the best. 7 mins long and it'll just make so much sense. Such a simple solution for when you have multiple text fields and want the scroll view to move "x" amount of pixels when that specific textfield is tapped.
https://youtu.be/VuiPGJOEBH4
Just these steps:
-Place all your textfields within a scrollview that is constrained to the edges of the view.
-Connect all the textfields and scroll view as delegates to the view controller.
-Connect all textfields and scroll view with an IBOutlet.
-Add UITextFieldDelegate protocol to your class
-Add UITextFieldDelegate methods to your swift file:
The first method just activates the return button on the keyboard to dismiss the keyboard. The second is when you tap into whatever specific textfield then setting the y offset of how far your scrollview scrolls (mine is based off of the y location on my view controllers 25,57,112,142). The last says when you tap away from the keyboard the scrollview goes back to original location.
I made my view pixel perfect this way!
it must be more stable
There have been som changes to how we define the KeyboardWillHideNotification.
This solution works with Swift 4.2:
Use following code for view Up on UITextField Clicked
I improved one of the answers a bit to make it work with different keyboards & different textviews/fields on one page:
Add observers:
Remove observers: