You can get the animation duration and the animation curve from the userInfo dictionary on the keyboardWillShow: notifications.
First register for the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
Then get the values from the notifications userInfo keys.
- (void)keyboardWillShow:(NSNotification*)notification {
NSNumber *duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [notification.userInfo objectForKey: UIKeyboardAnimationCurveUserInfoKey];
// Do stuff with these values.
}
There are a lot more of these keys, and you can also get them from the UIKeyboardWillDismiss notification.
This functionality is available all the way back to iOS 3.0 :D
Heres the docs:
https://developer.apple.com/documentation/uikit/uiresponder/1621576-keyboardwillshownotification
Swift Version
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
@objc func keyboardWillShow(_ notification: Notification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey]
let curve = notification.userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey]
}
Updated for latest swift version
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
private func keyboardWillShow(_ notification: Notification) {
let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
let animationCurve = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber
guard let duration = animationDuration, let curve = animationCurve else {
// values weren't available
return
}
let curveAnimationOption = UIView.AnimationOptions(rawValue: curve.uintValue)
UIView.animate(withDuration: duration, delay: 0.0, options: curveAnimationOption, animations: {
// do animations
print("ANIMATING---")
}, completion: { completed in
// completion block
print("COMPLETING---")
})
}