iPad 版 CGPathGetPathBoundingBox() 的替代方案 (iOS 3.2)
我正在尝试使用 QuartzCore 渲染半复杂的文本/渐变/图像 UITableViewCell 复合材料。值得庆幸的是,Opacity 可以让我直观地构建视图,然后吐出源代码以插入到 cocoa touch 中。问题是,Opacity 假定代码在 iOS 4 上运行,如果您想在 iPad 上绘制 Quartz 视图,这会是一个问题。
对我来说,有问题的方法是 CGPathGetPathBoundingBox ...有人介意向我指出这个(可能很简单)方法的合适替代方法或解决方法吗?
如果您想了解一些背景信息(没有双关语),请看这里:
transform = CGAffineTransformMakeRotation(1.571f);
tempPath = CGPathCreateMutable();
CGPathAddPath(tempPath, &transform, path);
pathBounds = CGPathGetPathBoundingBox(tempPath);
point = pathBounds.origin;
point2 = CGPointMake(CGRectGetMaxX(pathBounds), CGRectGetMinY(pathBounds));
transform = CGAffineTransformInvert(transform);
I'm trying to get my head around using QuartzCore to render semi-complex text/gradient/image UITableViewCell composites. Thankfully, Opacity will let me visually build the view and then spit out source code to drop in to cocoa touch. Trouble is, Opacity assumes the code is running on iOS 4, which is a problem if you want to draw Quartz views on an iPad.
For me, the offending method is CGPathGetPathBoundingBox ... would someone mind pointing me to a suitable alternative or workaround to this (presumably simple) method?
If you care to have some context (no pun intended), here you go:
transform = CGAffineTransformMakeRotation(1.571f);
tempPath = CGPathCreateMutable();
CGPathAddPath(tempPath, &transform, path);
pathBounds = CGPathGetPathBoundingBox(tempPath);
point = pathBounds.origin;
point2 = CGPointMake(CGRectGetMaxX(pathBounds), CGRectGetMinY(pathBounds));
transform = CGAffineTransformInvert(transform);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一种方法是 迭代路径上的点并自己记下锚点的最左、最右、最上和最下坐标,然后根据这些数字计算出原点和大小。
您应该将其包装在一个函数中,并将其命名为
MyPathGetPathBoundingBox
之类的名称,并使用它,直到放弃对 iOS 3.x 的支持。一旦可以,这将使您轻松切换到 CGPathGetPathBoundingBox。The alternative is to iterate on the points of the path and note down the leftmost, rightmost, upmost, and downmost co-ordinates of the anchor points yourself, then work out origin and size from those numbers.
You should wrap this in a function, and name it something like
MyPathGetPathBoundingBox
, and use that until you drop support for iOS 3.x. That will make it easy to switch toCGPathGetPathBoundingBox
once you can.