0

私は自分で使用しPinchGestureましたImageView。このコードは完全に実行されますが、今はZoomOutあるサイズで停止したいのですが、どうすればよいですか?

UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    panGesture.delegate=self;
    [overlayimageView addGestureRecognizer:panGesture];


- (void)handlePinch:(UIPinchGestureRecognizer *)recognizer
{

    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
}

こちら 開始イメージ

しかし、私は200 * 200以上をズームアウトしたくありません

4

1 に答える 1

1
CGFloat scale = 1.0 - (ImageLastScale - pinchscale);
CGRect bounds = [(UIPinchGestureRecognizer*)sender view].bounds;
scale = MIN(scale, maximumHeight / CGRectGetHeight(bounds));//define maximumHeight and minimumHeight for zoom level
scale = MAX(scale, minimumHeight / CGRectGetHeight(bounds));

メソッドを使用して、これを次のように使用します..hファイルでlastScale変数をFloatオブジェクトとして定義します

-(void)scale:(id)sender {

    if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
        lastScale = 1.0;
        return;
    }

    CGFloat pinchscale = [(UIPinchGestureRecognizer*)sender scale];
    CGFloat scale = 1.0 - (lastScale - pinchscale);
    CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
    CGAffineTransform holderTransform = holderView.transform;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
    [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];

    CGFloat scale = 1.0 - (lastScale - pinchscale);
    CGRect bounds = [(UIPinchGestureRecognizer*)sender view].bounds;
    scale = MIN(scale, maximumHeight / CGRectGetHeight(bounds));
    scale = MAX(scale, minimumHeight / CGRectGetHeight(bounds));

    lastScale = [(UIPinchGestureRecognizer*)sender scale];
}

更新しました

    UIPinchGestureRecognizer *pinchGesture=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(scale:)];
    pinchGesture.delegate=self;
    [overlayimageView addGestureRecognizer:pinchGesture];

この回答がお役に立てば幸いです..

于 2012-10-18T12:11:53.977 に答える