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 回答