[英]Using 2 UIPinchGestureRecognizers on the same UIImageView
I have an image view that I want to pinch to rescale without keeping the aspect ratio.我有一个图像视图,我想在不保持纵横比的情况下进行缩放以重新缩放。 In order to do this, I thought it might be feasible to either:
为了做到这一点,我认为这可能是可行的:
Here's my pinch handling function:这是我的捏处理 function:
- (void) pinch:(UIPinchGestureRecognizer *)recognizer {
static CGRect initialBounds;
if (recognizer.state == UIGestureRecognizerStateBegan)
{
initialBounds = imageView.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)recognizer scale];
//scale horizontally
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity,
factor-(1.0-factor), 1.0);
imageView.bounds = CGRectApplyAffineTransform(initialBounds, zt);
//now scale vertically
zt = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, factor);
imageView.bounds = CGRectApplyAffineTransform(initialBounds, zt);
return;
}
For some reason, the transform is only being done vertically (last one).由于某种原因,转换仅在垂直方向进行(最后一个)。 I tried changing the first parameter of the second CGRectApplyAffineTransform to imageView.bounds, but it still didn't work.
我尝试将第二个 CGRectApplyAffineTransform 的第一个参数更改为 imageView.bounds,但仍然没有用。
Can anyone please tell me where I am going wrong?谁能告诉我哪里出错了?
Also, when using two pinch gesture recognisers, the same thing happens - only one of them actually gets recognised.此外,当使用两个捏合手势识别器时,会发生同样的事情——实际上只有其中一个被识别出来。
Thanks!谢谢!
Your second one is starting with a CGAffineTransformIdentity.您的第二个以 CGAffineTransformIdentity 开始。 Instead, pass in the zt.
相反,传入 zt。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.