Created
July 16, 2015 17:14
-
-
Save jarsen/34c33995bf2445db35fc to your computer and use it in GitHub Desktop.
keyboard notifications
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
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