Skip to content

Instantly share code, notes, and snippets.

@bugrym
Created November 18, 2019 11:38
Show Gist options
  • Save bugrym/de5e476a1eefed6e24a5a8b2ea34ea1d to your computer and use it in GitHub Desktop.
Save bugrym/de5e476a1eefed6e24a5a8b2ea34ea1d to your computer and use it in GitHub Desktop.
Keyboard handler
@objc func adjustForKeyboard(notification: Notification) {
guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardScreenEndFrame = keyboardValue.cgRectValue
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame, from: view.window)
if notification.name == UIResponder.keyboardWillHideNotification {
scrollView.contentInset.bottom = self.logInButton.frame.height
} else {
let buttonPosition = self.logInButton.frame.origin.y + self.logInButton.frame.height
if buttonPosition > keyboardViewEndFrame.origin.y {
let inset = buttonPosition - keyboardViewEndFrame.origin.y
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: inset, right: 0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment