畫弧線方法
CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y, CGFloat radius,CGFloat startAngle, CGFloat endAngle, int clockwise)
理解:方法中的startAngle,endAngle,clockwise是相對于數(shù)學坐標(x軸向右,y軸向上)來說的递礼,但是由于ios中的坐標是x向右珊拼,y向下浆洗,因此最后得到的效果會是相對于x軸的鏡像。也就是繪制時嘶摊,是先按照x向右延蟹,y向上的坐標,以指定的方向進行繪制叶堆,然后獲得的弧線和方向以x為軸阱飘,做鏡像翻轉,這樣才獲得最終的圖形效果虱颗。
實際應用:
根據(jù)效果設置參數(shù):
1沥匈、使用數(shù)學坐標(x向右,y向上)時忘渔,先獲取需要的效果的起點高帖、終點位置及方向,然后將起點辨萍、終點及方向都取反棋恼,則獲得的參數(shù)即為填入方法中的參數(shù)返弹。
2、使用ios坐標(x向右爪飘,y向下)時义起,先取得需要的效果的起點、終點位置及方向师崎,然后只將方向取反默终,則起點、終點犁罩、取反后的方向即為填入方法中的參數(shù)齐蔽。
根據(jù)參數(shù)查看效果:
1、使用數(shù)學坐標(x向右床估,y向上)時含滴,將起點、終點及方向都取反
2丐巫、使用ios坐標(x向右谈况,y向下)時,只將方向取反
UIBezierPath畫弧
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise
通過UIBezierPath畫弧時递胧,方法中的startAngle,endAngle,clockwise是相對于ios坐標(x軸向右碑韵,y軸向下)來說的,也就是繪制時缎脾,直接按照x向右祝闻,y向下的坐標,以指定的方向進行繪制遗菠,不用用做翻轉联喘,直接得到最終的圖形效果。
例:
CGPoint centerPoint = CGPointMake(CGRectGetWidth(rect)/2, CGRectGetHeight(rect)/2);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor);
//CGContextRef畫弧
//CGContextMoveToPoint(context, centerPoint.x, centerPoint.y);
//CGContextAddArc(context, centerPoint.x, centerPoint.y, 100, 0, -M_PI_2, 1);
//UIBezierPath畫弧
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:centerPoint];
[bezierPath addArcWithCenter:centerPoint radius:100 startAngle:0 endAngle:-M_PI_2 clockwise:0];
CGContextAddPath(context, bezierPath.CGPath);
CGContextClosePath(context);
CGContextFillPath(context);
屏幕快照 2019-03-20 下午2.00.55.png