What is the animation speed of the keyboard appearing in iOS8? What is the animation speed of the keyboard appearing in iOS8? ios ios

What is the animation speed of the keyboard appearing in iOS8?

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:


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]}

The answer with the variable duration is right and work iOS 3 to 8, but with the new version of Swift, the answer's code is not working anymore.Maybe it is a mistake on my side, but I have to write:

let duration = aNotification.userInfo![UIKeyboardAnimationDurationUserInfoKey] as Doublelet curve = aNotification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as UIntself.view.setNeedsLayout()//baseConstraint.constant = 211self.view.setNeedsUpdateConstraints()UIView.animateWithDuration(duration, delay: 0.0, options: UIViewAnimationOptions(curve), animations: { _ in    //self.view.layoutIfNeeded()}, completion: { aaa in    //(value: Bool) in println()})

Looks like objectForKey is not working anymore and conversion is more strict.


    let duration = noti.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber    let curve = noti.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as! NSNumber    self.view.setNeedsLayout()    UIView.animate(withDuration: TimeInterval(duration), delay: 0, options: [UIViewAnimationOptions(rawValue: UInt(curve))], animations: {      self.view.layoutIfNeeded()    }, completion: nil)