Swift protocol extension for automatically adjusting ScrollView offset when keyboard appears/dissapears with only 2 lines of code required for setup propperly.
There is no any pod installation required!
- Drag KeyboardAwareScrollView file to you XCode project
- In you ViewController add conformance to the KeyboardAwareScrollView protocol
- Drag outlet for your UIScrollView in your ViewController and name it "scrollView"
- In your ViewDidLoad method add "self.setupKeyboardListener()"
class HomeViewController: UIViewController, KeyboardAwareViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
self.setupKeyboardListener()
}
}