gpt4 book ai didi

objective-c - 对路径中的变换参数使用 NULL 和 CGAffineTransformIdenity 之间的区别

转载 作者:行者123 更新时间:2023-12-03 17:03:25 24 4
gpt4 key购买 nike

以下各项之间是否有任何差异,特别是在性能方面:

方法 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之类的函数的文档,它会这样说:

m
A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Quartz applies the transformation to the point before changing the path.

由于 CGAffineTransformIdentity 本质上不是转换,因为它是身份,因此这两段代码实际上是相同的。

关于objective-c - 对路径中的变换参数使用 NULL 和 CGAffineTransformIdenity 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com