iostransformationcgaffinetransformcgaffinetransformscale

transformations in iOS and particullary Scaling


please correct me if I am wrong: if we have x=10, y=20, when we apply a transform on these coordinates (Lets say scaling x and y by 10), the new coordinates will be x=100 and y=200. So, if we apply scaling of x by -1 we get x= -10, y =20. But why this action causes the view to be mirrored? shouldn't the view just be re-drawn at it's new coordinates? What am I missing here ?


Solution

  • Don't think about a single coordinate, think about a range of coordinates.

    If you take the coords (x-value only here) of... 0, 1, 2, 3, 4 and scale them by 10 then they will map to 0, 10, 20, 30, 40 respectively. This will stretch out the x axis and so the view will look 10 times bigger than it did originally.

    If you take those same x coords and scale them by -1 then they will map to 0, -1, -2, -3, -4 respectively.

    That is, the pixel that is furthest away from the origin (4) is still furthest away from the origin but now at -4.

    Each pixel is mirrored through the origin.

    That's how scaling works in iOS, Android and general mathematics.

    If you just want to slide the view around without changing the size of it at all then you can use a translation instead.