Suragch - 8 months ago 44

Swift Question

I would like to apply multiple transforms to a

`UIView`

`UIView`

`CGAffineTransformConcat`

I have seen these questions:

but these questions are asking something different, and the given answers just talk about applying two transforms with

`CGAffineTransformConcat`

Answer

You can apply multiple transforms by stacking them on top of each other.

```
var t = CGAffineTransformIdentity
t = CGAffineTransformTranslate(t, CGFloat(100), CGFloat(300))
t = CGAffineTransformRotate(t, CGFloat(M_PI_4))
t = CGAffineTransformScale(t, CGFloat(-1), CGFloat(2))
// ... add as many as you want, then apply it to to the view
imageView.transform = t
```

This series of transforms produces the image on the right:

Thanks to this answer for teaching me how to do it.

The order in which you apply the transforms matters.

The CGAffineTransforms with `Make`

in their name *create* transformation matrices. You would use these if you only wanted to do a single transform or if you wanted to *start* a series of transforms with one of them. (In the example above we used `CGAffineTransformIdentity`

to create our initial matrix.)

- CGAffineTransform
**Make**Rotation - CGAffineTransform
**Make**Scale - CGAffineTransform
**Make**Translation

The following, which we used in our example, are used to add an additional transform to an existing matrix.

- CGAffineTransformTranslate
- CGAffineTransformScale
- CGAffineTransformRotate