首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >警告: CoreAnimation刚度必须大于0,但我使用viewAnimation

警告: CoreAnimation刚度必须大于0,但我使用viewAnimation
EN

Stack Overflow用户
提问于 2016-06-15 14:39:21
回答 1查看 2.3K关注 0票数 2

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

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

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

当我更改约束时,问题就会发生。

这是我的代码:

放大图像:

代码语言:javascript
复制
 @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
                })
            }
        }
    }

缩小图像:

代码语言:javascript
复制
@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
                })
            }
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-16 11:36:05

UIView动画是核心动画的高级包装器.在封面下,系统创建一个或多个CAAnimation对象以实现所请求的动画。

在这种情况下,听起来阻尼参数必须大于0,但这一要求不是由UIKit方法强制执行的--当系统将UIKit动画映射到核心动画时,它会生成一个错误。您得到的信息非常清楚地表明阻尼需要大于0,所以使用大于零的值。

我不知道什么是刚度。它必须是在底层核心动画调用中使用的参数,而不是在UIView动画调用中使用的。我猜当你使用一个>0的阻尼值时,这个错误就会消失。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37838559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档