A feature that needs to be done in the near future is to dynamically finish drawing a curve on the screen. This curve can be used to complete the description of the data in a certain period of time changes and so on. This is probably the effect below.
How is this effect going to be done? These three classes need to be used Uibezierpath cashapelayer and cabasicanimation. Where Uibezierpath is used to draw the corresponding curve path, Cashapelayer is used to provide a location for path presentation, and the animation created by Cabasicanimation is added to the path.
First we create the path we want:
Uibezierpath *path = [Uibezierpath Bezierpath]; [Path Movetopoint:cgpointmake (0.0,20.0)]; [Path Addlinetopoint:cgpointmake (120.0, 500.0)]; [Path Addlinetopoint:cgpointmake (0)]; [Path Addlinetopoint:cgpointmake (310, +)]; [Path Addlinetopoint:cgpointmake (Screen_width, 110)];
We then create our own properties for Cashapelayer and assign our path to it. Without this assignment, the layer will not be able to draw this effect for us, and it is also an incomplete layer.
Cashapelayer *pathlayer = [Cashapelayer layer]; Pathlayer.frame = self.view.bounds; Pathlayer.path = path. Cgpath; Pathlayer.strokecolor = [[Uicolor redcolor] cgcolor]; Pathlayer.fillcolor = nil; Pathlayer.linewidth = 2.0f; Pathlayer.linejoin = Kcalinejoinbevel; [Self.view.layer Addsublayer:pathlayer];
Finally, we assign the animation to our layer. In our animation effect, we can change some of the parameters to control its painting effect.
Cabasicanimation *pathanimation = [cabasicanimation animationwithkeypath:@ "Strokeend"]; Pathanimation = [cabasicanimation animationwithkeypath:@ "Strokeend"]; pathanimation.duration = 2.0; Pathanimation.fromvalue = [NSNumber numberwithfloat:0.0f]; Pathanimation.tovalue = [NSNumber numberwithfloat:1.0f]; [Pathlayer addanimation:pathanimation forkey:@ "Strokeend"];
Now that we run the code, we can get the effect from the previous picture ~
Dynamically draw curves on iOS