I was wondering if anyone knows how the UIPinchGestureRecognizer scale value is determined, or if there is a formula I could use to calculate a new scale value?
I have an app where I attach a UIPinchGestureRecognizer to an imageView, and in certain specific instances, I need to manually readjust a scale if it shrinks the imageView so it goes past a certain point of the screen. Thanks.
I found out what I needed by doing a little reverse engineering. As most of you know who have implemented a scale method with the UIPinchGestureRecognizer, you ultimately end up with this line of code:
This is the nextScale calculated on the value given by the UIPinchGestureRecognizer, however I needed to make my own custom scale since the user had scaled past the boundary I set up. So I determined the width I needed my imageview to be shrunk to, and determined the adjustedScale I needed by setting it up as a proportion: (nextScale / adjustedScale) = (nextWidth / adjustedWidth).
Then I reinserted the adjustedScale into the above formula to determine what the [sender scale] would be for my new scale amount: [sender scale] = AdjustedScale – 1 – previousScale.
So now I can use that amount to set the previousScale value which I’ll need for next time.