Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 对路径中的转换参数使用NULL和CGAffineTransformity的区别_Objective C_Cocoa_Core Graphics_Quartz 2d_Core Foundation - Fatal编程技术网

Objective c 对路径中的转换参数使用NULL和CGAffineTransformity的区别

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

以下各项之间是否存在任何差异,尤其是在性能方面:

方法1-使用空转换:

- (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
本质上不是转换,因为它是标识,因此这两段代码实际上是相同的。

您测量过吗?仪器可能会给你一些想法。效果是一样的,但如果你只指定一个身份转换,石英似乎会做额外的工作。这就是我想确认的(我知道——这是一个微不足道的问题,但好奇心会杀死那只猫;)