警告:CoreAnimation 刚度必须大于 0,但我使用 viewAnimation
Warning: CoreAnimation stiffness must be greater than 0, but I use viewAnimation
我不知道为什么,但是我突然得到这个警告,我以前没有得到:
CoreAnimation: stiffness must be greater than 0.
CoreAnimation: damping must be greater than or equal to 0.
CoreAnimation: stiffness must be greater than 0.
CoreAnimation: damping must be greater than or equal to 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
})
}
}
UIView 动画是对 Core Animation 的高级包装。在幕后,系统创建一个或多个 CAAnimation 对象以实现请求的动画。
在这种特殊情况下,听起来阻尼参数必须大于 0,但 UIKit 方法并未强制执行该要求 - 当系统将您的 UIKit 动画映射到 Core Animation 时,它会生成错误。您收到的消息非常清楚阻尼需要 > 0,因此请使用大于零的值。
我不确定什么是刚度。这必须是在 UIView 动画调用中未使用的底层 Core Animation 调用中使用的参数。我的猜测是,当您使用 > 0 阻尼值时,错误会消失。
我不知道为什么,但是我突然得到这个警告,我以前没有得到:
CoreAnimation: stiffness must be greater than 0.
CoreAnimation: damping must be greater than or equal to 0.
CoreAnimation: stiffness must be greater than 0.
CoreAnimation: damping must be greater than or equal to 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
})
}
}
UIView 动画是对 Core Animation 的高级包装。在幕后,系统创建一个或多个 CAAnimation 对象以实现请求的动画。
在这种特殊情况下,听起来阻尼参数必须大于 0,但 UIKit 方法并未强制执行该要求 - 当系统将您的 UIKit 动画映射到 Core Animation 时,它会生成错误。您收到的消息非常清楚阻尼需要 > 0,因此请使用大于零的值。
我不确定什么是刚度。这必须是在 UIView 动画调用中未使用的底层 Core Animation 调用中使用的参数。我的猜测是,当您使用 > 0 阻尼值时,错误会消失。