Я пытаюсь синхронизировать анимацию линии графика, круга и градиента.
Вот изображение GIF с несинхронизированной анимацией: / ![chart animation](https://giant.gfycat.com/MisguidedGentleFinch.gif)
Выполнить код всех анимаций:
CATransaction.begin()
CATransaction.setAnimationDuration(5.0)
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))
self?.animateLineDrawing()
self?.animateGradient()
self?.animateCircle()
CATransaction.commit()
Анимация рисования линий:
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.fromValue = 0.0
animation.toValue = 1.0
lineShapeLayer.add(animation, forKey: "drawLineAnimation")
lineShapeLayer.path = curvedPath.cgPath
У меня есть слой GrainContainer с градиентным слоем в качестве подслоя.Я перемещаю только слой маски контейнера поверх градиента. Слой:
let animationPath = UIBezierPath(rect: CGRect(x: firstPoint.x,
y: chartRect.origin.y,
width: 0,
height: chartRect.height))
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = animationPath.cgPath
animation.toValue = UIBezierPath(rect: CGRect(x: firstPoint.x,
y: chartRect.origin.y,
width: chartRect.width,
height: chartRect.height)).cgPath
animation.isRemovedOnCompletion = false
animation.fillMode = CAMediaTimingFillMode.forwards
animation.delegate = self
gradientContainerLayer.mask?.add(animation, forKey: nil)
Круговая анимация по траектории диаграммы:
let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = viewModel.curvedPath(frame)?.cgPath
animation.delegate = self
circleLayer.add(animation, forKey: nil)
Градиентная анимация не синхронизирована, поскольку расстояние по траекторииотличается от прямой, у кого-нибудь есть идеи, как синхронизировать это?
Почему синхронизация по кругу не равна линейной анимации?Похоже, начало и конец анимации одинаковы, поэтому функции синхронизации разные, почему?