是否可以通过使用指定的点作为锚来缩放图像,即图像从这一点“增长”?
答案 0 :(得分:1)
缩放不是基于一个观点。你想要做的是移动它,使新图像和原始图像上的对应点在同一点。为此,只需调整图像的(x,y)位置即可。使用与边缘成比例的距离乘以大小差异。
答案 1 :(得分:0)
你可以做这样的事情(基于使用UIPinchGesureRecognize的解决方案,但你可以得到这个想法......)。 这是为gestureRecognizer调用的选择器:
CGPoint newDistanceFromCenter;
CGPoint distanceFromCenter;
- (void) scale:(id)sender
{
UIPinchGestureRecognizer *recognizer = (UIPinchGestureRecognizer*)sender;
if(recognizer.state == UIGestureRecognizerStateBegan)
{
CGPoint pinchPoint = [recognizer locationInView:self];
distanceFromCenter.x = self.center.x - pinchPoint.x;
distanceFromCenter.y = self.center.y - pinchPoint.y;
}
else if(recognizer.state == UIGestureRecognizerStateChanged)
{
CGAffineTransform currentTransform = self.transform;
CGFloat scale = recognizer.scale;
newDistanceFromCenter.x = (distanceFromCenter.x * scale);
newDistanceFromCenter.y = (distanceFromCenter.y * scale);
CGPoint center = scalingImage_.center;
center.x -= (distanceFromCenter.x - newDistanceFromCenter.x);
center.y -= (distanceFromCenter.y - newDistanceFromCenter.y);
self.center = center;
distanceFromCenter = newDistanceFromCenter;
self.transform = CGAffineTransformScale(currentTransform, scale, scale);
recognizer.scale = 1;
}
}