From 10e58b876bb79ae0c443f2c7c236da208d07125c Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Sun, 28 Oct 2018 23:07:02 -0700 Subject: [PATCH] Fix lineDashPhase not set for Stroke.offset bug --- .../ShapeAnimationGenerator.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/animation/types/animation_generators/ShapeAnimationGenerator.swift b/Source/animation/types/animation_generators/ShapeAnimationGenerator.swift index efc584b8..74048e6a 100644 --- a/Source/animation/types/animation_generators/ShapeAnimationGenerator.swift +++ b/Source/animation/types/animation_generators/ShapeAnimationGenerator.swift @@ -107,6 +107,7 @@ func addShapeAnimation(_ animation: BasicAnimation, sceneLayer: CALayer, animati layer.lineCap = MCAShapeLayerLineCap.mapToGraphics(model: stroke.cap) layer.lineJoin = MCAShapeLayerLineJoin.mapToGraphics(model: stroke.join) layer.lineDashPattern = stroke.dashes.map { NSNumber(value: $0) } + layer.lineDashPhase = CGFloat(stroke.offset) } else if shape.fill == nil { layer.strokeColor = MColor.black.cgColor layer.lineWidth = 1.0 @@ -201,6 +202,16 @@ fileprivate func generateShapeAnimation(from: Shape, to: Shape, duration: Double group.animations?.append(dashPatternAnimation) } + + // Dash offset + if fromStroke.offset != toStroke.offset{ + let dashOffsetAnimation = CABasicAnimation(keyPath: "lineDashPhase") + dashOffsetAnimation.fromValue = fromStroke.offset + dashOffsetAnimation.toValue = toStroke.offset + dashOffsetAnimation.duration = duration + + group.animations?.append(dashOffsetAnimation) + } // Group group.duration = duration