我有一个UIImageView在UIScrollview。我使用了Apple的docs中的说明。UIImageView在UIScrollView,缩放是不安的
我设置了最小和最大缩放比例。 (0.5和6.0)。我将代表设置为self。
我在viewForZoomingInScrollView中返回了图像视图。但是我不知道该怎么做scrollViewDidEndZooming。
我遇到的结果是一个抖动缩放,并不一致。它只是不像照片库应用程序。
我错过了什么吗?
我有一个UIImageView在UIScrollview。我使用了Apple的docs中的说明。UIImageView在UIScrollView,缩放是不安的
我设置了最小和最大缩放比例。 (0.5和6.0)。我将代表设置为self。
我在viewForZoomingInScrollView中返回了图像视图。但是我不知道该怎么做scrollViewDidEndZooming。
我遇到的结果是一个抖动缩放,并不一致。它只是不像照片库应用程序。
我错过了什么吗?
这是唯一的解决方案,我发现工作完美无瑕。它包括双击和两个手指手势来放大和缩小。 http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
//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文件中
希望它能对您有用...
变焦工程进展顺利,但图像有时运行时间超过,而我认为这是因为滚动视图的泛权:当你有像做这样的准备设置开始缩放比例。当我放大更多时,平底锅有时会干扰变焦和平底锅。我应该完全消除scrollview并在imageview上实现平移手势吗?无论如何,有没有办法让它像ios上的照片应用一样?谢谢 – Madhu
您还可以为scrollview设置最大和最小比例属性以获取更多信息,请点击此处查看[http://navaneethant.wordpress.com/2010/06/30/zooming-and-scrolling-in-uiscrollviewiphone-application /) – Alex
将您的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;
非常感谢,它解决了我的问题。我正在使用contentMode比例来适应哪些导致了不安的效果。 –
接受你的答案,以便将来帮助他人。 –