我在UIScrollview中有一个UIImageView。我使用了Apple的docs中的说明。
我设置了最小和最大缩放比例。 (0.5和6.0)。我把代表设置为自己。
我在viewForZoomingInScrollView中返回了图像视图。但是我不知道在scrollViewDidEndZooming中要做什么。
我的结果是抖动变焦并且不一致。它只是不像照片库应用程序。
我错过了什么吗?
答案 0 :(得分: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:method
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}
在此之前添加.h文件
希望它对你有用......
答案 1 :(得分:1)
将ImageView缩放内容模式设置为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;
答案 2 :(得分:0)
这是我发现完美无瑕的唯一解决方案。它包括双击和两个手指手势放大和缩小。 http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content