Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Last active August 1, 2018 22:22
Show Gist options
  • Select an option

  • Save meyusufdemirci/a9c9d3581cce00f046b324deb475254c to your computer and use it in GitHub Desktop.

Select an option

Save meyusufdemirci/a9c9d3581cce00f046b324deb475254c to your computer and use it in GitHub Desktop.
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardFrame = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue {
let keyboardRectangle = keyboardFrame.cgRectValue
keyboardHeight = keyboardRectangle.height
}
if view.frame.origin.y == 0 {
let animationDuration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey]
UIView.animate(withDuration: animationDuration as! TimeInterval) {
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: (self.view.window?.frame.height)! - self.keyboardHeight)
self.view.layoutIfNeeded()
}
}
}
@objc func keyboardWillHide(_ notification: Notification) {
UIView.animate(withDuration: 0.2) {
self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: UIScreen.main.bounds.height)
self.view.layoutIfNeeded()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment