Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying CGAffineTransform to CGPath

Tags:

ios

iphone

ipad

What I am trying to do is to apply a CGAffineTransform to a CGPath.

I know, if I were drawing onto a CGContext, I would just transform the context itself.

But what I want to do is to apply a transform to the actual path itself. UIBezierPath allows me do to this with the applyTransform: method, it doesn't transform it's CGPath.

Is there any way to apply a CGAffineTransform to a CGPath itself??

like image 982
Saurav Sachidanand Avatar asked Dec 17 '11 13:12

Saurav Sachidanand


1 Answers

You can use CGPathCreateCopyByTransformingPath which creates a copy of your path, transformed by a given CGAffineTransform. There's also CGPathCreateMutableCopyByTransformingPath for creating a mutable copy.

Note that both of these functions have been introduced in iOS 5.

If you need something that works on earlier versions of iOS, you could create an empty path (CGPathCreateMutable) and add your other path with CGPathAddPath which optionally takes a transformation as its second parameter.

like image 70
omz Avatar answered Nov 10 '22 00:11

omz