我使用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;
}
答案 0 :(得分: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];
它应该适用于所有事情(进/出)。