I am trying to scale multiple UIViews at once with the pinch gesture(On the base view). Though it looked straight forward, I am facing hard time getting it working properly.
Assume I have 3 views stacked like this
----------------------------------------------
| |
| ------- -------- |
| | | | | |
| | V1 | --------------- | | |
| | | X | v2 | Y | v3 | |
| ------- --------------- | | |
| -------- |
---------------------------------------------
On pinch, I am scaling each of the 3 views by calculating the transform using the scale propery
CGAffineTransform v1Transform = CGAffineTransformScale( v1.transform,recognizer.scale, recognizer.scale);
v1.transform = v1Transform
CGAffineTransform v2Transform = CGAffineTransformScale( v2.transform,recognizer.scale, recognizer.scale);
v2.transform = v2Transform
CGAffineTransform v3Transform = CGAffineTransformScale( v3.transform,recognizer.scale, recognizer.scale);
v3.transform = v3Transform
And change the center of each view using the current scale, like this
CGPoint v1Center = CGPointMake(v1.center.x * recognizer.scale, node.imgView.center.y * recognizer.scale);
CGPoint v2Center = CGPointMake(v2.center.x * recognizer.scale, node.imgView.center.y * recognizer.scale);
CGPoint v3Center = CGPointMake(v3.center.x * recognizer.scale, node.imgView.center.y * recognizer.scale);
v1.cente = v1Center;
v2.center = v2Center;
v3.center = v3Center;
Though this scales each of the 3 views uniformly, I feel the center point is too off and the scaling looks weirder. please check the below screen capture of the issue
As you can see, though the scale works as expected and all 3 views scale together. Center is still an issue. I want the scale to be done from all 3 views actual place, I dont want them to move like this in the gif.
Is there a way? any help is much appreciated