代码之家  ›  专栏  ›  技术社区  ›  Bruno Bieri

UIBezierPath支持相对路径?

  •  0
  • Bruno Bieri  · 技术社区  · 6 年前

    我把苹果的文档读到了 UIBezierPath 对象我是否正确理解了它不支持相对路径?

    我试图将此svg路径转换为UIBezierPath:

    // svg path
    m90 36c-7 0-13 6-13 13s6 13 13 13 13-6 13-13-6-13-13-13zm-27 32c-7 0-13 6-13 13s6 13 13 13 13-6 13-13-6-13-13-13z
    

    我从以下方面开始:

    UIBezierPath* myPath = [UIBezierPath bezierPath];
    CGPoint currentPoint;
    
    [myPath moveToPoint:CGPointMake([self sizeDependendX:90], [self sizeDependendY:36])];
    currentPoint = CGPathGetCurrentPoint(myPath.CGPath);
    [myPath addCurveToPoint:CGPointMake(currentPoint.x - 13, currentPoint.y + 13)
              controlPoint1:CGPointMake(currentPoint.x +  7, currentPoint.y +  0)
              controlPoint2:CGPointMake(currentPoint.x - 13, currentPoint.y +  6)];
    currentPoint = CGPathGetCurrentPoint(myPath.CGPath);
    [myPath addCurveToPoint:CGPointMake(currentPoint.x + 13 ,currentPoint.y + 13)
              controlPoint1:CGPointMake(currentPoint.x +  0, currentPoint.y +  7)
              controlPoint2:CGPointMake(currentPoint.x +  6, currentPoint.y + 13)];
    ...
    

    是真的要这样还是我错过了什么?

    0 回复  |  直到 5 年前
        1
  •  2
  •   Fattie    6 年前

    事实上,有

    (如果真的需要的话,制作一个扩展、函数或其他一些糖来使其整洁是很简单的

    go(across: 7.0, down: -2.5)
    go(across: 4.0, down: -2.5)
    go(across: 7.0, down: -2.5)
    

    .. 有点像。这只是您想要的函数或扩展的几行代码。)

    很抱歉听到这个坏消息!:)


    我们做了很多与贝塞尔相关的事情,下面是一些典型的代码。我使用了无数的助手调用,因此代码更有意义。

    enter image description here