是否有任何区别,特别是在以下性能方面:
方法 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;
}
我猜他们是完全一样的,但想确认一下。