iOS程序猿

UIBezierPath画圆弧 addArcWithCenter

2016-09-01  本文已影响3406人  一个城市猎人

UIBezierPath画圆弧 addArcWithCenter

UIBezierPath通过
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise
可以画出一段弧线。
看下各个参数的意义:
center:圆心的坐标
radius:半径
startAngle:起始的弧度
endAngle:圆弧结束的弧度
clockwise:YES为顺时针,No为逆时针
方法里面主要是理解startAngle与endAngle,刚开始我搞不清楚一段圆弧从哪算起始和终止,比如弧度为0的话,是从上下左右哪个点开始算
看了下面这张图就明了了
![](https://img.haomeiwen.com/i1361069/9396924d2f620514?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
看出0Pi就是指圆最右边开始计算的,顺时针依次为M_PI/2,M_PI,M_PI*1.5
明白这个,用BezierPath画圆弧就简单了
比如要画上图加粗的那段就是:


UIBezierPath *path = [[UIBezierPath alloc] init];    
[path addArcWithCenter:center    
                radius:radius    
            startAngle:M_PI*1.1    
              endAngle:M_PI*1.9    
             clockwise:YES];    

上一篇下一篇

猜你喜欢

热点阅读