问题描述
在我看来,我有一张图片.图片具有3:2的比例,并且在分辨率方面非常大.
In my view I have a picture.. The picture has a 3:2 scale and is huge, resolution wise.
用图像将UIImage初始化为原始大小,然后缩小UIImageView以使整个图像在滚动视图中可见时,我遇到了很多麻烦.
I'm having a lot of trouble initializing a UIImage with the image to the original size and then zooming out of the UIImageView so that the entire image is visible within the scrollview.
程序仅以纵向放置.
不,请不要只使用UIWebView.UIWebView不允许我在视图加载期间设置内容大小...相反,它只是以任意缩放比例缩小图像,我无法找到一种调整缩放值的方法(我不认为这是可能).
And no, please don't say to just use UIWebView. UIWebView doesn't let me set the content size during view load...instead, it just zooms out of the image by some arbitrary scale and I couldn't figure out a way to adjust the scale value (I don't think it's possible).
感谢您的任何答复!我真的很感谢他们:D
Thanks for any responses! I really appreciate them :D
推荐答案
下面是放置响应于缩放的图像的示例.基本上,您将 UIImageView
放在 UIScrollView
中并更改一些设置.
Here's an example of placing an image that responds to pinch-to-zoom. Basically, you place the UIImageView
in a UIScrollView
and change some settings.
UIImageView *myImage;
UIScrollView *myScroll;
-(void)viewDidLoad{
myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,360,450)];
[myImage setImage:[UIImage imageNamed:@"coolpic.png"]];
myImage.contentMode = UIViewContentModeScaleAspectFit;
[myScroll addSubview:myImage];
[myScroll setContentSize:CGSizeMake(myImage.frame.size.width, myImage.frame.size.height)];
[myScroll setMinimumZoomScale:1.0];
[myScroll setMaximumZoomScale:4.0];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return myImage;
}
当然,请正确设置所有代表和IB挂钩.
Of course, set all your delegates and IB hooks properly.
我只是重新阅读了您的问题.示例中回答您的问题的部分是UIImageView的框架规范及其 contentMode
设置.
I just reread your question. The portion of the example that answers your question is the frame specification of the UIImageView and its contentMode
setting.
这篇关于如何使用UIImageView调整图片的大小,以便可以放大和缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!