简体   繁体   中英

Need examples for how to use CGAffineTransform in CGPaths

I don't understand how to apply "CGAffineTransform" parameter that appears in practically every CGPath method, eg:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM