views:

71

answers:

1

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);
+1  A: 

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 to CGPathGetPathBoundingBox once you can.

Peter Hosey
I see another function that is similar in description, but I'm not sure if it's identical in functionality ... CGPathGetBoundingBox ... I can't quite tell the difference between this and CGPathGetPathBoundingBox.
Greg Combs
Greg Combs: The difference is that `CGPathGetBoundingBox` takes control points into account, so for a curve segment, the entire area covered by the curve will contribute to the bounding box. `CGPathGetPathBoundingBox` only considers the anchor points, so curves are effectively measured as if they were straight lines. As a pathological case, a circle made of two curveto segments would have no area at all (since there's nothing but a straight line between the two anchor points), whereas a polygon (nothing but lineto's) would have area.
Peter Hosey
Greg Combs: Or, visually: http://i.imgur.com/cF7SS.png
Peter Hosey
This is a brilliant explanation. *Thank*you* !
Greg Combs