I would like to apply multiple transforms to a UIView
(or subclass of UIView
), such as translate, rotate, and scale. I know that two transforms can be applied with CGAffineTransformConcat
, but how do I do it if I have three or more transforms?
I have seen these questions:
but these questions are asking something different, and the given answers just talk about applying two transforms with CGAffineTransformConcat
. Also, they use Objective-C rather than Swift.
You can apply multiple transforms by stacking them on top of each other.
Or more compactly (but not necessarily as readable):
This series of transforms produces the image on the right:
Thanks to this answer for teaching me how to do it.
Notes
The order in which you apply the transforms matters. For example, if the transforms were done in the opposite order it would produce the following result.
See also
This answer has been tested with Swift 4