Last active
October 13, 2021 21:00
-
-
Save blazovics/f38dbea158868b2671dcf5628f10b0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 private func keyboardWillShow(notification: Notification) { | |
if let userInfo = notification.userInfo, let keyboardSize = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { | |
if passwordTextField.frame.maxY > (view.frame.height - keyboardSize.height) { | |
imageViewTopConstraint.constant = -1 * (passwordTextField.frame.maxY - (view.frame.height - keyboardSize.height)) | |
} | |
} | |
} | |
@objc private func keyboardWillHide(notification: Notification) { | |
imageViewTopConstraint.constant = 0 | |
} |
This file contains hidden or 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 private func keyboardWillShow(notification: Notification) { | |
if let userInfo = notification.userInfo, | |
let keyboardSize = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue, | |
let duration = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue { | |
if passwordTextField.frame.maxY > (view.frame.height - keyboardSize.height) { | |
UIView.animate(withDuration: duration, animations: { | |
self.imageViewTopConstraint.constant = -1 * (self.passwordTextField.frame.maxY - (self.view.frame.height - keyboardSize.height)) | |
self.view.layoutIfNeeded() | |
}) | |
} | |
} | |
} | |
@objc private func keyboardWillHide(notification: Notification) { | |
if let userInfo = notification.userInfo, | |
let duration = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue { | |
UIView.animate(withDuration: duration) { | |
self.imageViewTopConstraint.constant = 0 | |
self.view.layoutIfNeeded() | |
} | |
} | |
} |
This file contains hidden or 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
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
NotificationCenter.default.addObserver(self, selector: #selector(LoginViewController.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(LoginViewController.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
NotificationCenter.default.removeObserver(self) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment