1
votes

I am using the following library to rotate, scale and move images ZoomRotatePanImageView

The problem is that moving images is missed up if used after rotation as it tries to move the image according to the new angle it has instead of the pan gesture direction.

i.e. when rotating the image 180 degrees then trying to move it to the right it moves left instead (all directions is reversed)

here is the code for UIPanGestureRecognizer which is using CGAffineTransformTranslate to manipulate the image

- (IBAction) handlePan:(UIPanGestureRecognizer*)recogniser {
    if (recogniser.state == UIGestureRecognizerStateCancelled) {
        recogniser.view.transform = originalImageViewTransform;
        return;
    }

    if (recogniser.state == UIGestureRecognizerStateBegan) {
        originalImageViewTransform = recogniser.view.transform;
    }

    CGAffineTransform transform = recogniser.view.transform;
    CGPoint translation = [recogniser translationInView:self.superview];
    transform = CGAffineTransformTranslate(transform, translation.x, translation.y);


    [recogniser setTranslation:CGPointZero inView:self]; // This line means we don't need prevRotation

    if (recogniser.state == UIGestureRecognizerStateEnded) {
        // The gesture ended, so push an undo action before setting the transform.
        [self setTransform:transform ofView:recogniser.view undoTransform:originalImageViewTransform];
        if ([self.delegate respondsToSelector:@selector(saveImageStateWithTag:)])
            [self.delegate saveImageStateWithTag:self.tag];
    } else {
        // The gesture changed but didn't end, so don't push an undo action.
        recogniser.view.transform = transform;
    }
}

so how to make the image moves according to the original dimensional space not the new one?

1

1 Answers

1
votes

change the following line from

CGPoint translation = [recogniser translationInView:self.superview];

to

CGPoint translation = [recogniser translationInView:self];

will fix your problem