UIButton iOS 7 following UIKeyboard animation

风格不统一 提交于 2019-12-13 08:51:50

问题


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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/18968899/uibutton-ios-7-following-uikeyboard-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!