When scaling an image view using the UIPinchGestureRecognizer when the action is ongoing the image "tries" to remain at the initial frame.origin.
Even after a pan gesture has moved the image to another location a pinch promptly moves it back to the initial location.
All of the code for this blatant copy of Apple's Touches sample app that demonstrates gestures.
Below is the code for pinch, I have pushed a sample app on github demonstrating this behavior: https://github.com/atokubi/TestImageManipulation
Thanks in advance for your assistance.
- (IBAction)scaleItem:(UIPinchGestureRecognizer *)gestureRecognizer {
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
[gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
[gestureRecognizer setScale:1];
}
}
- (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UIView *piece = gestureRecognizer.view;
CGPoint locationInView = [gestureRecognizer locationInView:piece];
CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];
piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;
}
}