Func Animation1 (layerparam:cashapelayer) {let animation = cabasicanimation (keypath: "Strokestart") Animation.fromvalue = 0 animation.tovalue = 1 animation.duration = 2.0 layerparam.addanimation (animation , Forkey: "") }
This code can be used to achieve the drawing of the curve animation, Fromvalue and Tovalue respectively represents the animation starting point and the endpoint, 0 for the startpoint,1 represents endpoint, the entire path can be regarded as the unit 1,0.5 and other intermediate values are also possible. Don't forget to add the function
Self.animation1 (layer)
Ignore that mouse ...
It can also be written in the middle to both sides of the effect
Func Animation2 (layerparam:cashapelayer) { Layerparam.strokestart = 0.5 layerparam.strokeend = 0.5 Let Animation1 = Cabasicanimation (keypath: "Strokestart") animation1.fromvalue = 0.5 animation1.tovalue = 0 Animation1.duration = 2 let animation2 = cabasicanimation (keypath: "Strokeend") Animation2.fromvalue = 0.5 animation2.tovalue = 1 animation2.duration = 2 layerparam.addanimation (Animation1, Forkey: "") Layerparam.addanimation (Animation2, Forkey: "") }
The following effect can be obtained with linewidth
Func Animation3 (layerparam:cashapelayer) {let animation = cabasicanimation (keypath: "LineWidth") Animation.fromvalue = 1 animation.tovalue = animation.duration = 2 layerparam.addanimation ( Animation, Forkey: "") }
Round rectangles can be implemented in any of these.
Uibezierpath curve Animation for iOS development