1

是否有任何区别,特别是在以下性能方面:

方法 1 - 使用 NULL 变换:

- (CGPathRef)createPathForRect:(CGRect)rect
{
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, rect.size.width / 2, rect.size.height - 1);
    CGPathAddLineToPoint(path, NULL, (rect.size.width / 2) - 20, rect.size.height - 22);
    CGPathAddLineToPoint(path, NULL, 0, rect.size.height - 22);
    CGPathAddLineToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, rect.size.width - 1, 0);
    CGPathAddLineToPoint(path, NULL, rect.size.width - 1, rect.size.height - 22);
    CGPathAddLineToPoint(path, NULL, (rect.size.width / 2) + 20, rect.size.height - 22);
    CGPathCloseSubpath(path);
    return path;
}

方法 2 - 使用身份转换:

- (CGPathRef)createPathForRect:(CGRect)rect
{
    CGAffineTransform transform = CGAffineTransformIdentity;
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, &transform, rect.size.width / 2, rect.size.height - 1);
    CGPathAddLineToPoint(path, &transform, (rect.size.width / 2) - 20, rect.size.height - 22);
    CGPathAddLineToPoint(path, &transform, 0, rect.size.height - 22);
    CGPathAddLineToPoint(path, &transform, 0, 0);
    CGPathAddLineToPoint(path, &transform, rect.size.width - 1, 0);
    CGPathAddLineToPoint(path, &transform, rect.size.width - 1, rect.size.height - 22);
    CGPathAddLineToPoint(path, &transform, (rect.size.width / 2) + 20, rect.size.height - 22);
    CGPathCloseSubpath(path);
    return path;
}

我猜他们是完全一样的,但想确认一下。

4

1 回答 1

2

如果您查看文档以获取诸如 之类的函数CGPathMoveToPoint,它会说:

m
指向仿射变换矩阵的指针,如果不需要变换,则为 NULL。如果指定,Quartz 在改变路径之前应用变换到点。

由于CGAffineTransformIdentity本质上没有转换,因为它是恒等式,因此这两个代码实际上是相同的。

于 2013-10-28T12:20:01.460 回答