我想通过下面的代码为我的循环progressView创建一个动画。我希望动画开始从0到我想要的值的进度。 但我永远无法让动画工作。
migration.deleteData(CustomObject.className()) // If needed
migration.enumerate(User.className()) { oldObject, newObject in
if let oldObject = oldObject,
let newObject = newObject {
let oldCustomObject = oldObject["customObject"] as! MigrationObject
let newCustomObject = migration.create(CustomObject.className(), value: oldCustomObject)
let customObjectList = newObject["customObjectList"] as! List<MigrationObject>
customObjectList.append(newCustomObject)
}
}
答案 0 :(得分:8)
使用CABasicAnimation
let circle = Pop
var progressCircle = CAShapeLayer()
let circlePath = UIBezierPath(ovalInRect: circle.bounds)
progressCircle = CAShapeLayer ()
progressCircle.path = circlePath.CGPath
progressCircle.strokeColor = UIColor.greenColor().CGColor
progressCircle.fillColor = UIColor.clearColor().CGColor
progressCircle.lineWidth = 5.0
circle.layer.addSublayer(progressCircle)
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.fromValue = 0
animation.toValue = 0.2
animation.duration = 3
animation.fillMode = kCAFillModeForwards
animation.removedOnCompletion = false
progressCircle.addAnimation(animation, forKey: "ani")
答案 1 :(得分:2)
两件事 -
首先 - 不要重新初始化progressCircle
。您正在拨打progressCircle = CAShapeLayer ();
两次。这不是错误。
秒 - 在开始设置动画之前添加子图层。将circle.layer.addSublayer(progressCircle);
移到动画块之外。