CGContextAddArcToPoint 学习笔记

1,675 阅读1分钟

CGContextAddArcToPoint 学习笔记

今天学习了大牛博客,发现对标题所说的属性一知半解,还能怎么办,继续百度呗。于是找到了一个比较满意的答案:正解。10分感谢🙏

个人理解

  1. arcToPoint 中的后面两个点,是两个参考点。

2.画出来的线,起点从 currentPoint 开始 ,终止于另一条切线的切点。

测试

UIImageView *testView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
    testView.backgroundColor = [UIColor yellowColor];
    // 开启上下文
    UIGraphicsBeginImageContext(testView.frame.size);
    // 开始绘制
    [testView.image drawInRect:CGRectMake(0, 0, testView.frame.size.width, testView.frame.size.height)];   
    // 获取上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    // 设置边框宽度
    CGContextSetLineWidth(context, 3);
    // 设置边框颜色
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    
    // A:(20,20)   B:(120,20)  C:(120,100)
    CGContextMoveToPoint(context, 20, 20);
    
    //以下三行是辅助线  可以注释掉
    CGContextAddLineToPoint(context, 120, 20);
    CGContextAddLineToPoint(context, 120, 100);
    CGContextMoveToPoint(context, 20, 20);
    
    CGContextAddArcToPoint(context, 120, 20, 120, 100, 50);
    CGContextDrawPath(context, kCGPathFillStroke);
    testView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.view addSubview:testView];

图片效果(AB,BC两条辅助线都是切线):

WX20170706-165800.png

WX20170706-165844.png

特殊情况

当AB,BC 距离相等,弧的半径 = AB= BC 的时候 ,路径就是一条弧,起始于A,终止于C ,如图:

WX20170706-172755.png

tip

以上为个人学习笔记,如有不对的地方,多请指正,3Q🌚。