Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created July 16, 2015 17:14
Show Gist options
  • Save jarsen/34c33995bf2445db35fc to your computer and use it in GitHub Desktop.
Save jarsen/34c33995bf2445db35fc to your computer and use it in GitHub Desktop.
keyboard notifications
func keyboardWillShow(notification: NSNotification) {
print("Showing keyboard")
guard let userInfo = notification.userInfo,
rectValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue,
rawCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? UInt,
duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? Double else {
return
}
let keyboardFrame = rectValue.CGRectValue()
let options = UIViewAnimationOptions(rawValue: rawCurve)
UIView.animateWithDuration(duration, delay: 0, options: options, animations: {
self.textViewBottomContraint.constant = keyboardFrame.height
}, completion: { completed in
})
}
func keyboardWillHide(notification: NSNotification) {
guard let userInfo = notification.userInfo,
rawCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? UInt,
duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? Double else {
return
}
let options = UIViewAnimationOptions(rawValue: rawCurve)
UIView.animateWithDuration(duration, delay: 0, options: options, animations: {
self.textViewBottomContraint.constant = 0
}, completion: { completed in
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment