Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active December 2, 2018 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/b5e43d085e2b97875f29043fa34b8c50 to your computer and use it in GitHub Desktop.
Save laevandus/b5e43d085e2b97875f29043fa34b8c50 to your computer and use it in GitHub Desktop.
final class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
private var keyboardObserver: KeyboardObserver?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
keyboardObserver = KeyboardObserver(changeHandler: { [weak self] (info) in
guard let self = self else { return }
switch info.event {
case .willShow:
self.scrollView.contentInset.bottom = info.endFrame.height
case .willHide:
self.scrollView.contentInset.bottom = 0
default:
break
}
})
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
keyboardObserver = nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment