0

我使用 GestureRecognizer 代表来捏合图像。我使用 UIPinchGestureRecognizer 代表进行捏合。但是,当我捏​​缩放时它没有任何问题。当我缩小某个级别时,图像会从视图中消失。

代码:

UIPinchGestureRecognizer *pinchGesture1 = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(ahandlePinch1:)];

 [myImageView addGestureRecognizer:pinchGesture1];

-(void)ahandlePinch1:(UIPinchGestureRecognizer*)sender {



    mCurrentScale += [sender scale] - mLastScale;
    mLastScale = [sender scale];

    if (sender.state == UIGestureRecognizerStateEnded)
    {
        mLastScale = 1.0;
    }

    CGAffineTransform currentTransform = CGAffineTransformIdentity;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, mCurrentScale, mCurrentScale);
    myImageView.transform = newTransform;

}
4

1 回答 1

0

做这个 :

 if([pinch state] == UIGestureRecognizerStateEnded)
    {

        lastScale = 1.0;
        return;
    }

    CGFloat scale = 1.0 - (lastScale - [pinch scale]);

    CGAffineTransform currentTransform = myImageView.transform;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);

    [myImageView setTransform:newTransform];

    lastScale = [pinch scale];

它应该适用于一切(进/出)。

于 2013-07-09T12:19:38.507 回答