以下各项之间是否有任何区别,特别是在性能方面:
方法 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;
}
我猜它们完全相同,但想确认这一点。
如果您查看诸如 CGPathMoveToPoint
之类的函数的文档,它是这样说的:
米
指向仿射转换矩阵的指针,如果不需要转换,则为 NULL。如果指定,Quartz 将在更改路径之前将变换应用于该点。
由于CGAffineTransformIdentity
本质上不是转换,因为它是标识,因此这两段代码实际上是相同的。