Need examples using CGAffineTransform in CGPaths

I donโ€™t understand how to apply the CGAffineTransform parameter, which appears in almost every CGPath method, for example:

void CGPathAddRect ( CGMutablePathRef path, const CGAffineTransform *m, CGRect rect ); 

Let's say I want to turn the straight path, how would I write out this function? Where can I get the transformation matrix?

+6
ios iphone quartz-graphics cgaffinetransform
source share
1 answer

You use CGAffineTransformMakeRotation to create a CGAffineTransform that rotates a rectangle around a 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 around any other points (x, y), you need to make 2 translations to move (x, y) to (0, 0) and vice versa.

+7
source share

All Articles