在UIScrollView中缩放UIImageView,在滑动图像时导致偏移

时间:2012-06-20 17:34:27

标签: iphone ios uiscrollview uiimageview

我正在尝试使用捏合手势缩放UIImageView,如下面的代码所示:

- (void)scaleImage:(UIPinchGestureRecognizer *)recognizer
{
    if([recognizer state] == UIGestureRecognizerStateEnded)
    {
        previousScale = 1.0;
        scrollView.contentSize = CGSizeMake(imageViewPic.frame.size.width, imageViewPic.frame.size.height);
        return;
    }
    CGFloat newScale = 1.0 - (previousScale - [recognizer scale]);
    CGAffineTransform currentTransformation = imageViewPic.transform;
    CGAffineTransform newTransform = CGAffineTransformScale(currentTransformation, newScale, newScale);
    imageViewPic.transform = newTransform;
    previousScale = [recognizer scale];
}

我的问题是,如果我尝试移动新缩放的图像,它会从底部和右边偏移(如下图所示),我无法从顶部和左边完全向下移动(有些地方我没看到)。我究竟做错了什么?我得到了图像视图从转换中获得的新宽度和高度,这些值不是我应该在滚动视图内容中使用的新值吗?

enter image description here

0 个答案:

没有答案