Search code examples
iosswiftcgaffinetransform

Scaling the UIView resets rotation


I am using this code to scale the view :

view.transform = CGAffineTransform(scaleX: 2, y: 2)

It scales the view perfectly, But problem is that:

If I rotate the view first and then scale it, in this case also scaling works as required but it resets the rotation.

It should not reset the rotation.


Solution

  • You are creating a transform that only has a scale and you are then applying just that scale to the view.

    You want to apply the scale transform to the existing transform.

    view.transform = view.transform.scaledBy(x: 2, y: 2)