質問

I would like to animate a UIButton which is at the bottom of my UIView when the keyboard becomes/resigns first responder. Before iOS 7 I made a simple animation that moves the button, but now the animation of the keyboard is non linear, it starts faster and ends more slowly. I've been told to do it with the new UIKit Dynamics but don't have any idea of how can I achieve my goal. Any suggestion?

Thanks in advance.

役に立ちましたか?

解決

Listen to keyboard notifications. There you can obtain the following information and animate your button accordingly.

UIKeyboardAnimationCurveUserInfoKey The key for an NSNumber object containing a UIViewAnimationCurve constant that defines how the keyboard will be animated onto or off the screen.

Available in iOS 3.0 and later.

Declared in UIWindow.h.

UIKeyboardAnimationDurationUserInfoKey The key for an NSNumber object containing a double that identifies the duration of the animation in seconds.

Available in iOS 3.0 and later.

Declared in UIWindow.h.

More information here: https://developer.apple.com/library/ios/documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/doc/constant_group/Keyboard_Notification_User_Info_Keys

他のヒント

possible duplicate, another possible duplicate

@Leo: I've tried using those values but they didn't work for me (and others I've seen), so I ended up with this:

[UIView animateWithDuration:0.5
                      delay:0
     usingSpringWithDamping:500.0f
      initialSpringVelocity:0.0f
                    options:UIViewAnimationOptionCurveLinear
                 animations:animBlock
                 completion:completionBlock];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top