Reputation: 14571
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
?).
Upvotes: 1
Views: 719
Reputation: 391
var currentZoomScale: CGFloat = 1.0
...
@objc
private func handlePinch(_ sender: UIPinchGestureRecognizer) {
mainContentView.transform = mainContentView.transform.scaledBy(x: sender.scale, y: sender.scale)
currentZoomScale *= sender.scale
sender.scale = 1
}
Upvotes: 0
Reputation: 11307
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;
Upvotes: 0
Reputation: 6089
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.
Upvotes: 0
Reputation: 28767
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.
Upvotes: 0