Created
November 18, 2019 11:38
-
-
Save bugrym/de5e476a1eefed6e24a5a8b2ea34ea1d to your computer and use it in GitHub Desktop.
Keyboard handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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