Skip to content

Commit

Permalink
Merge pull request #497 from fangpenlin/fang/bugfix-496/line-dash-pha…
Browse files Browse the repository at this point in the history
…se-not-set-for-stroke-offset-animation-bug

Fix lineDashPhase not set for Stroke.offset bug
  • Loading branch information
ystrot authored Oct 29, 2018
2 parents edda796 + 10e58b8 commit 6714da4
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6714da4

Please sign in to comment.