Objective c 对路径中的转换参数使用NULL和CGAffineTransformity的区别
以下各项之间是否存在任何差异,尤其是在性能方面: 方法1-使用空转换:Objective c 对路径中的转换参数使用NULL和CGAffineTransformity的区别,objective-c,cocoa,core-graphics,quartz-2d,core-foundation,Objective C,Cocoa,Core Graphics,Quartz 2d,Core Foundation,以下各项之间是否存在任何差异,尤其是在性能方面: 方法1-使用空转换: - (CGPathRef)createPathForRect:(CGRect)rect { CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, rect.size.width / 2, rect.size.height - 1); CGPathAddLineToPoint(path, NULL, (r
- (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;
}
- (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;
}
方法2-使用身份转换:
- (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;
}
- (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
,它会这样说:
m指向仿射变换矩阵的指针,如果不需要变换,则为NULL。如果指定,Quartz将在更改路径之前对点应用变换
由于
CGAffineTransformity
本质上不是转换,因为它是标识,因此这两段代码实际上是相同的。您测量过吗?仪器可能会给你一些想法。效果是一样的,但如果你只指定一个身份转换,石英似乎会做额外的工作。这就是我想确认的(我知道——这是一个微不足道的问题,但好奇心会杀死那只猫;)