http://blog.csdn.net/yixiangboy/article/details/50662704 First, case demonstration
Recently there is a small need to make a circular progress bar, the approximate appearance is as follows:
。
Without knowing the Strokestart and Strokeend properties of the Cashapelayer, I took the method of removing the old cashapelayer in real time and redrawing the circular cashapelayer. Obviously, the efficiency of this approach is not high. Later at a time to see others demo, found that others use Cashapelayer Strokestart and Strokeend properties, to achieve this effect is very simple and convenient. Let's talk about the use of these two properties.
Second, attribute detailed
Apple's official explanations for these two properties are:
/* These values define the subregion of the path used to draw the
* Stroked outline. The values must is in the range [0,1] with zero
* Representing the start of the path and one the end. Values in
* Between zero and one are interpolated linearly along the path
* length. Strokestart defaults to zero and strokeend to one. Both is
* animatable. */
The idea is that we can partition the drawn path. The values of these two properties are between 0~1, 0 represents the start of path, and 1 represents the end position of path. is a linear increment relationship. Strokestart default value is 0,strokeend default is 1. Both of these properties support animations.
Cashapelayer *shapelayer = [Cashapelayer layer]; Shapelayer. frame = _demoview. Bounds; Shapelayer. Strokeend =0.7f; Shapelayer. Strokestart =0.1f; Uibezierpath *path = [Uibezierpath bezierpathwithovalinrect:_demoview.bounds].path = Path.fillcolor = [UIColor clearColor]< Span class= "Hljs-preprocessor". Cgcolor.linewidth = 2.0f.layer addsublayer:shapelayer]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
We use the above code to set: strokestart=0.1f; The strokeend=0.7f is displayed as shown.
Three, round progress bar implementation code
In conclusion, we know that Strokestart and Strokeend can set the starting and ending positions of a path, and by using the two properties of Strokestart and Strokeend, we can realize the effect of the circular progress bar through the following code.
Cashapelayer *shapelayer = [Cashapelayer layer]; Shapelayer. frame = _demoview. Bounds; Uibezierpath *path = [Uibezierpath bezierpathwithovalinrect:_demoview. Bounds]; Shapelayer. Path = Path. Cgpath; Shapelayer. FillColor = [Uicolor Clearcolor]. Cgcolor; Shapelayer. LineWidth =2.0f; Shapelayer. Strokecolor = [Uicolor Redcolor]. Cgcolor; [_demoview. Layer Addsublayer:shapelayer]; Cabasicanimation *pathanima = [Cabasicanimation animationwithkeypath:@"Strokeend"]; Pathanima.duration = 3.0f pathAnima< Span class= "hljs-preprocessor" >.timingfunction = [camediatimingfunction functionwithname: Kcamediatimingfunctioneaseineaseout]0.0f] PathAnima.tovalue = [nsnumber numberwithfloat:1.0f] .fillmode = Kcafillmodeforwards; Pathanima.removedoncompletion = No; [Shapelayer Addanimation:pathanima forkey:@ "strokeendanimation"]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
Iv. Contact information
Weibo: Sina Weibo
Blog: http://blog.csdn.net/yixiangboy
Github:https://github.com/yixiangboy
-
Top
-
0
iOS Development Basics--cashapelayer Strokestart and Strokeend properties