I don't understand how to apply "CGAffineTransform" parameter that appears in practically every CGPath method, e.g.:
void CGPathAddRect (
CGMutablePathRef path,
const CGAffineTransform *m,
CGRect rect
);
Let's say I want to rotate a rect path, how would I write out this function? Where to I get the transform matrix?
You use use CGAffineTransformMakeRotation to create a CGAffineTransform that rotates the rectangle about the point (0, 0).
CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI / 4); // π/4 = 45°
CGPathAddRect(path, &rotation, CGRectMake(0, 0, 80, 40));
If you need it to rotate about any other points (x, y), you need to compose 2 translations to move (x, y) to (0, 0) and back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With