0

我使用GestureRecognizer委託捏圖像。我使用UIPinchGestureRecognizer委託進行捏合。但是,當我捏​​zoomIn它沒有任何問題。當我zoomOut特定級別的圖像從視圖中消失。圖像已經確定縮小級別

代碼:

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

這樣做:

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]; 

它應該一切工作(輸入/輸出)。