【发布时间】: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