gpt4 book ai didi

iphone - 我在 ImageView 中使用了 PinchGesture。此代码运行完美,现在我想在某个尺寸处停止 ZoomOut,我该怎么办?

转载 作者:行者123 更新时间:2023-11-29 04:21:21 25 4
gpt4 key购买 nike

我在我的ImageView中使用了PinchGesture。此代码运行完美,现在我想在某个尺寸处停止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;
}

here Starting image

but i does not want to ZoomOut More than 200*200

最佳答案

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

使用方法,我像下面这样使用它。将lastScale变量定义为.h文件中的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];

希望这个回答对你有帮助..

关于iphone - 我在 ImageView 中使用了 PinchGesture。此代码运行完美,现在我想在某个尺寸处停止 ZoomOut,我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com