UIImageView捏放大UIScrollView [英] UIImageView pinch zooming in UIScrollView
本文介绍了UIImageView捏放大UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对使用UIScrollView进行捏缩放功能感到满意.但是问题是滚动视图中图像的长宽比合适.
I am comfortable with pinch zooming functionality using UIScrollView. But the problem is the aspect fit of image in scrollview.
目前,我在图片下方有这个图片:
Currently, I am having this, below image:
但是我希望图像能像下面的图像一样适合屏幕:
But I want image to be fit in screen like below image:
与风景的行为相同.我该如何实现?
And same behavior for landscape. How can I achieve this?
下面是代码:
- (void)viewDidLoad
{
UIImage *image = [UIImage imageWithData:appDelegate.selectedOriginalImage];
imgView.image = image;
CGSize imageSize = image.size;
CGRect rect = CGRectMake(0, 0, imageSize.width, imageSize.height);
imgView.frame = rect;
scrollView.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 1.0;
scrollView.delegate = self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIImage *image = [UIImage imageWithData:appDelegate.selectedOriginalImage];
CGSize imageSize = image.size;
CGRect rect = CGRectMake(0, 0, imageSize.width, imageSize.height);
imgView.frame = rect;
[scrollView setContentOffset:CGPointMake(0, 0)];
return YES;
}
推荐答案
您正在将UIImageView设置为图像的原始大小,而不是包含图像的UIScrollView的大小.
You are setting the UIImageView to the original size of the image instead of the size of the UIScrollView that contains it.
- (void)viewDidLoad
{
UIImage *image = [UIImage imageWithData:appDelegate.selectedOriginalImage];
imgView.image = image;
imgView.frame = scrollView.bounds;
[imgView setContentMode:UIViewContentModeScaleAspectFit];
scrollView.contentSize = CGSizeMake(imgView.frame.size.width, imgView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 1.0;
scrollView.delegate = self;
}
记住要在viewToZoom委托方法上返回imgView
remember to return the imgView on the viewToZoom delegate method
这篇关于UIImageView捏放大UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文