deb*_*k63 3 core-graphics cgpath ios uibezierpath
我在x和y方向上按比例2缩放UIBezierPath(由一个[0,0 - 1x1] rect构建).UIBezierPath".bounds"没问题(即按预期缩放),而".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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
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}}
Run Code Online (Sandbox Code Playgroud)
为什么?
从iOS 5.1开始,当应用了新的转换时,CGPath返回UIBezier的.CGPath属性确实已更新UIBezierPath.
但是,这并不排除旧iOS版本的解决方案.你可以得到CGPath从UIBezierPath直接改造它,然后将其放回UIBezierPath.瞧,所有其他属性,如边界和起源,将立即正确更新.
UIBezierPath* path = [UIBezierPath bezierPathWithRect:CGRectMake(0.0f, 0.0f,
1.0f, 1.0f)];
CGAffineTransform transform = CGAffineTransformMakeScale(2.0f, 2.0f);
CGPathRef intermediatePath = CGPathCreateCopyByTransformingPath(path.CGPath,
&transform);
path.CGPath = intermediatePath;
CGPathRelease(intermediatePath);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5134 次 |
| 最近记录: |