【发布时间】:2019-06-16 07:39:02
【问题描述】:
当每个条形图为 UIView 时,我已经编写了一个条形图,并对其高度和超级视图的顶部约束进行了限制。
输入高度值后,应执行持续时间为 10 秒的动画。
但是,动画没有出现。
我先计算条的新高度:
let portion = Float(self.currentValue!) / Float(self.maxValue!) // portion of max height of the bar
let newTopConstraint = Float(maxTopConstraint) * portion // the new distance from the top of the superview
var heightDiff = newTopConstraint - Float(self.barTopConstraint.constant)
heightDiff = abs(heightDiff)
现在我得到了条的新高度,我想将它动画到那个位置:
UIView.animate(withDuration: 10) {
self.barTopConstraint.constant = newTopConstraint
self.heightCons.constant += heightDiff
self.barView.setNeedsLayout()
}
不幸的是,动画永远不会出现。我的动画有什么问题?
【问题讨论】: