Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created August 13, 2018 22:07
Show Gist options
  • Select an option

  • Save Arrlindii/15646c3efbe8f07a72f4bd099f5ffd57 to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/15646c3efbe8f07a72f4bd099f5ffd57 to your computer and use it in GitHub Desktop.
func configureKeyboardListeners() {
NotificationCenter.default.addObserver(forName: Notification.Name.UIKeyboardWillShow, object: nil, queue: nil) { notification in
let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! CGRect
let keyboardHeight: CGFloat = keyboardFrame.height
self.scrollView.contentInset.bottom = keyboardHeight
self.scrollView.scrollIndicatorInsets.bottom = keyboardHeight
}
NotificationCenter.default.addObserver(forName: Notification.Name.UIKeyboardWillHide, object: nil, queue: nil) { notification in
self.scrollView.contentInset.bottom = 0
self.scrollView.scrollIndicatorInsets.bottom = 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment