1

I have a UIImageView in a UIScrollview. I used the instructions in Apple's docs.

I set minimum and maximum zoom scales. (0.5 and 6.0). I set the delegate to self.

I returned the image view in viewForZoomingInScrollView. However I don't know what to do in scrollViewDidEndZooming.

The result I am having is a jittery zoom and not consistent. It is just not behaving like the photo gallery app.

Am I missing something?

4

3 回答 3

2
//create imageview with pinchGesture

        CGRect myImageRect = CGRectMake(17, 95, 285, 130);
        myImage = [[UIImageView alloc] initWithFrame:myImageRect];
        [myImage setImage:[UIImage imageNamed:picture]];
        myImage.userInteractionEnabled = YES;
        UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
                                         initWithTarget:self action:@selector(handlePinch:)];
        pgr.delegate = self;
        [myImage addGestureRecognizer:pgr];
        [scrollview addSubview:myImage];

// handlepinch: 方法

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
 recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform,   recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}

在此之前添加 .h 文件

希望它对你有用...

于 2013-06-25T07:36:10.657 回答
1

将您的 ImageView 缩放 contentMode 设置为 UIViewContentModeCenter 并在加载时缩小(如果需要)。当您准备好图像时,通过执行以下操作设置起始缩放比例:

        //Min scale is how much ever it takes to fit the image in the view
        CGRect scrollViewFrame = self.scrollView.frame;
        CGFloat scaleWidth = scrollViewFrame.size.width / self.imageView.image.size.width;
        CGFloat scaleHeight = scrollViewFrame.size.height / self.imageView.image.size.height;
        CGFloat minScale = MIN(scaleWidth, scaleHeight);
        self.scrollView.minimumZoomScale = minScale;
        self.scrollView.zoomScale = minScale;
于 2013-10-08T21:29:36.193 回答
0

这是我发现工作完美的唯一解决方案。它包括双击和两个手指手势来放大和缩小。http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

于 2013-06-26T01:28:20.923 回答