Question

Suppose the current scale of my UIView is x. Suppose I apply a scale transformation to my UIView of the amount y ie:

view.transform = CGAffineTransformScale(view.transform, y, y);

. How do I determine what the value of the scale of the UIView after the scale transformation occurs (in terms of x and y?).

Was it helpful?

Solution

The scale transform multiplies the current scale with your scale y. if the scale was 2.0 for retina, it is y* 2.0 afterwards.
So x*y is the answer. but dont forget x.achsis scale and y achsis can be different.
x, and y for scale is confusing, better use s1 and s2, or sx, sy if you have different scale on y and x achsis, in your code.

OTHER TIPS

Scaling combines by multiplication, translation (movement) by addition, rotation is a matrix multiplication. All three can be combined into an AffineTransformation (a matrix with 1 more row than the dimensions of the space), these are combined by matrix multiplication. 2D AffineTransformations are 3x2 or 3x3 matrices, the extra column just makes them easier to work with.

Edit: Using clearer names: if he current scale was currxs, currys and the scale applied was xs,ys the new scale would be currxs*xs, currys*ys. Note that applying a scale will also scale any translation component that is contained in the AffineTransformation, this is why order of application is important.

Its quite simple if you are just using the CGAffineTransformScale and not the other transformations like rotation, you can use the view frame and bounds size to calculate the resulting scale values.

float scaleX = view.frame.size.width/view.bounds.size.width;
float scaleY = view.frame.size.height/view.bounds.size.height;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top