【问题标题】:UIKeyboardWillChangeFrameNotification UIViewAnimationCurve set to 7 on iOS 7UIKeyboardWillChangeFrameNotification UIViewAnimationCurve 在 iOS 7 上设置为 7
【发布时间】:2013-10-29 05:45:30
【问题描述】:

我希望确定键盘的动画效果。在 iOS 6 上,我得到了 UIKeyboardAnimationCurveUserInfoKey 的有效值(应该是 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}}";
}}

【问题讨论】:

标签: ios uikeyboard


【解决方案1】:

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

但你仍然可以使用它。要将其转换为块动画的 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];

或者只是将其作为动画曲线传入。

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

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:keyboardTransitionAnimationCurve];
// ... do stuff here
[UIView commitAnimations];

【讨论】:

  • 第二种方法,我发现在iOS10上可能会崩溃
【解决方案2】:

很遗憾,我无法发表评论,否则我不会输入新答案。

你也可以使用:

animationOptions |= animationCurve

这可能是首选,因为它将保留以前对动画选项的 OR = 操作。

【讨论】:

    【解决方案3】:

    在 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)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 2012-10-16
      • 2014-07-03
      • 2013-10-07
      • 2016-10-26
      • 2015-11-27
      相关资源
      最近更新 更多