UIKeyboardWillChangeFrameNotification UIViewAnimationCurve在iOS 7上设置为7

UIKeyboardWillChangeFrameNotification UIViewAnimationCurve在iOS 7上设置为7,ios,uikeyboard,Ios,Uikeyboard,我期待着确定键盘将如何在动画中。在iOS 6上,我为UIKeyboardAnimationCurveUserInfo键(它应该是UIViewAnimationCurve,值为0-3)获取一个有效值,但函数返回的值为7。键盘是如何在中设置动画的?使用值7可以做什么 NSConcreteNotification 0xc472900 {name = UIKeyboardWillChangeFrameNotification; userInfo = { UIKeyboardAnimationCu

我期待着确定键盘将如何在动画中。在iOS 6上,我为
UIKeyboardAnimationCurveUserInfo键
(它应该是
UIViewAnimationCurve
,值为0-3)获取一个有效值,但函数返回的值为7。键盘是如何在中设置动画的?使用值7可以做什么

NSConcreteNotification 0xc472900 {name = UIKeyboardWillChangeFrameNotification; userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 7;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
    UIKeyboardFrameChangedByUserInteraction = 0;
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
}}

键盘似乎正在使用未记录/未知的动画曲线

但你仍然可以使用它。若要将其转换为UIViewAnimationOptions,块动画的选项将其移动16位,如下所示

UIViewAnimationCurve keyboardTransitionAnimationCurve;
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey]
                           getValue:&keyboardTransitionAnimationCurve];

keyboardTransitionAnimationCurve |= keyboardTransitionAnimationCurve<<16;

[UIView animateWithDuration:0.5
                  delay:0.0
                options:keyboardTransitionAnimationCurve
             animations:^{
                // ... do stuff here
           } completion:NULL];

不幸的是,我不能发表评论,否则我将不输入新答案

您还可以使用:

动画选项|=Swift 4中的动画曲线

func keyboardWillShow(_ notification: Notification!) {
    if let info = notification.userInfo {
        let keyboardSize = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
        let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double 
        let curveVal = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue ?? 7 // default value for keyboard animation
        let options = UIView.AnimationOptions(rawValue: UInt(curveVal << 16))
        UIView.animate(withDuration: duration, delay: 0, options: options, animations: {
        // any operation to be performed
    }, completion: nil)
    }
}
func键盘将显示(u通知:通知!){
如果let info=notification.userInfo{
将keyboardSize=info[UIResponder.keyboardFrameEndUserInfoKey]设为?cRect
将duration=info[UIResponder.keyboardAnimationDurationUserInfoKey]设为?双精度
设curveVal=(信息[UIResponder.KeyboardAnimationCurveUserInfo]为?NSNumber)?.intValue±7//键盘动画的默认值

让options=UIView.AnimationOptions(rawValue:UInt(curveVal)参见&对于第二种方法,我发现它可能会在iOS10上崩溃
func keyboardWillShow(_ notification: Notification!) {
    if let info = notification.userInfo {
        let keyboardSize = info[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
        let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double 
        let curveVal = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.intValue ?? 7 // default value for keyboard animation
        let options = UIView.AnimationOptions(rawValue: UInt(curveVal << 16))
        UIView.animate(withDuration: duration, delay: 0, options: options, animations: {
        // any operation to be performed
    }, completion: nil)
    }
}