【发布时间】:2016-01-14 16:37:27
【问题描述】:
删除动画后保留动画 UIView 属性的正确方法是什么?
具体来说,目标是为 10 秒的进度条设置动画。
如果用户在 5 秒后停止,进度条应保持在 5 秒。相反,一旦动画被移除,它会跳转到 10 秒,即最终值。
到目前为止,唯一的解决方案是使用一个类变量,但它似乎很老套,并且少一个要跟踪的变量是理想的。没有类变量这可能吗?
我们尝试使用来自presentationLayer 的值,如下所示,但也失败了。
private func animateProgressBar(recording: Bool) {
// Stop animation if not recording
if (!recording) {
print("Stopped recording")
progressBar.layer.removeAllAnimations()
return
}
// If here, animate progress bar
view.layoutIfNeeded()
UIView.animateWithDuration(VideoDur, delay: 0.0, options: .CurveLinear, animations: {
self.progressBarWidthConstraint.constant = self.view.frame.width
self.view.layoutIfNeeded()
}, completion: { finished in
if (finished) {
self.endRecording()
} else {
self.progressBarWidthConstraint.constant = self.progressBar.layer.presentationLayer()!.frame.width
self.view.layoutIfNeeded()
}
})
}
【问题讨论】:
标签: ios swift uiview uikit uiviewanimation