我在x和y方向上用因子2縮放UIBezierPath(由一個[0,0 - 1x1]矩形構建)。 UIBezierPath 「.bounds」 是正常的(即如預期比例),而 「.CGPath」 保持不變...關於UIBezierPath + applyTransform + CGPath的困惑
代碼:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0,
1, 1)];
NSLog(@"path.bounds box before transform:%@",
NSStringFromCGRect(path.bounds));
NSLog(@"path.CGPath box before transform:%@",
NSStringFromCGRect(CGPathGetBoundingBox(path.CGPath)));
[path applyTransform:CGAffineTransformMakeScale(2, 2)];
NSLog(@"path.bounds box after transform:%@",
NSStringFromCGRect(path.bounds));
NSLog(@"path.CGPath box after transform:%@",
NSStringFromCGRect(CGPathGetBoundingBox(path.CGPath)));
return 0;
}
輸出:
path.bounds box before transform:{{0, 0}, {1, 1}}
path.CGPath box before transform:{{0, 0}, {1, 1}}
path.bounds box after transform:{{0, 0}, {2, 2}}
path.CGPath box after transform:{{0, 0}, {1, 1}}
爲什麼?
此代碼導致嚴重的內存泄漏。 –
感謝您指出這一點;的確如此。我忘了添加'CGPathRelease(intermediatePath);'來釋放你擁有的臨時文件。 –