Ios7 收缩手势缩放仅从左上角缩放UIImage

Ios7 收缩手势缩放仅从左上角缩放UIImage,ios7,uiview,xcode5,pinchzoom,uipinchgesturerecognizer,Ios7,Uiview,Xcode5,Pinchzoom,Uipinchgesturerecognizer,我对这一点还不太熟悉,我正在尝试使用收缩手势来放大图像,并能够放大图像的任何特定部分。但是,当我缩放时,它仅从UIView的左上角缩放。所以我只能看到放大的图像的左上角。我希望能够缩放/平移图像,类似于照片应用程序的工作方式。以下是我目前的代码: 在ViewDidLoad中: ... // Load the image to be viewed into the UIImage self.theImage.image = self.theNewImage; UIPinchGestureRec

我对这一点还不太熟悉,我正在尝试使用收缩手势来放大图像,并能够放大图像的任何特定部分。但是,当我缩放时,它仅从UIView的左上角缩放。所以我只能看到放大的图像的左上角。我希望能够缩放/平移图像,类似于照片应用程序的工作方式。以下是我目前的代码:

在ViewDidLoad中:

...
 // Load the image to be viewed into the UIImage
self.theImage.image = self.theNewImage;

UIPinchGestureRecognizer *pinchGestRecog = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];

// ADD GESTURE RECOGNIZER TO THE VIEW
[theImage addGestureRecognizer:pinchGestRecog];

// ALLOW USER INTERACTION ON THE VIEW
[theImage setUserInteractionEnabled:YES];

// SET IMAGE ZOOM SCALE LIMITS
imageCurrentScale = 1.0;
imageMaxScale = 2.0;
imageMinScale = 0.5;
然后在我的twoFingerPinch方法中:

 - (void)twoFingerPinch:(UIPinchGestureRecognizer *)aPinchGesture
{
if (imageCurrentScale * [aPinchGesture scale] > imageMinScale && imageCurrentScale * [aPinchGesture scale] < imageMaxScale) {

    imageCurrentScale = imageCurrentScale * [aPinchGesture scale];
    CGAffineTransform zoomTransform = CGAffineTransformMakeScale(imageCurrentScale, imageCurrentScale);
    [[aPinchGesture view] setTransform:zoomTransform];
}
[aPinchGesture setScale:1.0];
-(void)twoFingerPinch:(UIPinchgEstureRecognitor*)APinch手势
{
如果(imageCurrentScale*[ApinchHistorage scale]>imageMinScale&&imageCurrentScale*[ApinchHistorage scale]
}

淘金就是答案吗?我真的不确定平移是如何工作的。
有什么建议吗?谢谢。

之所以缩放到左上角,是因为缩放变换的中心是
UIView.layer.anchorPoint
,默认为左上角(0,0)。 如果你想正确地缩放,你必须找出你捏手势的中心,然后将你的主播点设置到那个位置

但无论如何,你不应该那样做。放大
UIImageView
的推荐方法是将图像视图放置在
UIScrollView
中,并相应地设置
contentSize
maximumZoomScale
minimumZoomScale
值。 将自己设置为
UIScrollView
的代理,并在
viewForZooming
delegate方法中返回
UIImageView

scrollview将为您处理收缩和缩放