Skip to content

Instantly share code, notes, and snippets.

@Pretz
Last active December 9, 2015 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/10b4b11806263b556761 to your computer and use it in GitHub Desktop.
Save Pretz/10b4b11806263b556761 to your computer and use it in GitHub Desktop.
Gets the info from a UIKeyboardWill(Show/Hide)Notification and returns it in a not-terrible tuple
public func keyboardInfoFromUserInfo(userInfo: [NSObject: AnyObject]) -> (beginFrame: CGRect, endFrame: CGRect, animationCurve: UIViewAnimationOptions, animationDuration: Double)? {
if let beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue,
let endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue,
let animationCurve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber,
let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber {
return (
beginFrame: beginFrameValue.CGRectValue(),
endFrame: endFrameValue.CGRectValue(),
animationCurve: UIViewAnimationOptions(rawValue: animationCurve.unsignedIntegerValue << 16),
animationDuration: animationDuration.doubleValue)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment