【问题标题】:Warning: CoreAnimation stiffness must be greater than 0, but I use viewAnimation警告:CoreAnimation 刚度必须大于 0,但我使用 viewAnimation
【发布时间】:2016-10-16 18:04:19
【问题描述】:

我不知道为什么,但我突然得到了这个警告,我以前没有得到:

CoreAnimation:刚度必须大于 0。

CoreAnimation:阻尼必须大于或等于 0。

CoreAnimation:刚度必须大于 0。

CoreAnimation:阻尼必须大于或等于 0。

对于我的动画,我使用viewAnimation,这不是来自框架UIKit吗?因为阻尼,刚度来自layerAnimation,而这来自框架CoreAnimation

当我更改约束时会出现问题。

这是我的代码:

放大图片:

 @IBAction func posterButton(sender: AnyObject) {
        
        // Unhide poster
        poster.hidden = false
        
        // Show poster:
        for constraint in poster.superview!.constraints {
            
            if constraint.identifier == "EnlargePoster" {
                
                constraint.active = false
                
                let newConstraint = NSLayoutConstraint(item: self.poster, attribute: .Bottom, relatedBy: .Equal, toItem: self.poster.superview!, attribute: .Bottom, multiplier: 1, constant: 0)
                
                newConstraint.identifier = "EnlargePoster"
                newConstraint.active = true
                
                UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: [], animations: {
                    
                    self.view.layoutIfNeeded()
                    
                    }, completion: {_void in
                        
                        // show poster close button
                        self.hidePosterButton.hidden = false
                })
            }
        }
    }

缩小图片:

@IBAction func hidePoster(sender: AnyObject) {
        
        // hide poster:
        for constraint in poster.superview!.constraints {
            
            if constraint.identifier == "EnlargePoster" {
                
                constraint.active = false
                
                let newConstraint = NSLayoutConstraint(item: self.poster, attribute: .Bottom, relatedBy: .Equal, toItem: self.poster.superview!, attribute: .Bottom, multiplier: 1, constant: -672)
                
                newConstraint.identifier = "EnlargePoster"
                newConstraint.active = true
                
                UIView.animateWithDuration(0.6, delay: 0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: [], animations: {
                    
                    self.view.layoutIfNeeded()
                    
                    }, completion: {_void in
                        
                        // Hide poster
                        self.poster.hidden = true
                })
            }
        }

【问题讨论】:

    标签: swift animation core-animation uiviewanimation


    【解决方案1】:

    UIView 动画是核心动画的高级封装。在幕后,系统会创建一个或多个 CAAnimation 对象以实现所请求的动画。

    在这种特殊情况下,阻尼参数听起来必须大于 0,但 UIKit 方法并未强制执行该要求 - 当系统将您的 UIKit 动画映射到核心动画时,它会生成错误。您收到的消息非常清楚地表明阻尼需要 > 0,因此请使用大于零的值。

    我不确定什么是刚度。这必须是在 UIView 动画调用中未使用的基础核心动画调用中使用的参数。我的猜测是,当您使用 > 0 的阻尼值时,错误就会消失。

    【讨论】:

    • 谢谢。有效。为什么我没有想出那个。当在 viewAnimation 中设置为 0 是可能的时,我发现为什么会收到该警告很奇怪。但再次感谢。
    • 如果这回答了您的问题,那么您应该点击复选框接受它。
    猜你喜欢
    • 2016-01-28
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多