Skip to content

Instantly share code, notes, and snippets.

@blazovics
Last active February 24, 2020 08:36
Show Gist options
  • Save blazovics/447b421bd6ff187fce8995280351a343 to your computer and use it in GitHub Desktop.
Save blazovics/447b421bd6ff187fce8995280351a343 to your computer and use it in GitHub Desktop.
@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 -=
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, animations: { self.imageViewTopConstraint.constant =
UIDevice.current.orientation == .portrait ? 160 : 40
self.view.layoutIfNeeded()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment