如何使用UIImageView调整图片大小以便我可以放大和缩小?

K-R*_*RAN 2 iphone uiscrollview uiimageview uiimage

在我看来,我有一张照片..图片的比例为3:2,分辨率很高.

我在将图像初始化为原始大小的UIImage,然后缩小UIImageView以便整个图像在滚动视图中可见时遇到了很多麻烦.

该程序仅保留纵向.

不,请不要说只使用UIWebView.UIWebView不允许我在视图加载期间设置内容大小...相反,它只是按照任意比例缩小图像,我无法找到调整比例值的方法(我不认为它是可能).

谢谢你的回复!我真的很感激他们:D

B_.*_*B_. 10

以下是放置响应缩放的图像的示例.基本上,你放入UIImageView一个UIScrollView并更改一些设置.

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;
}
Run Code Online (Sandbox Code Playgroud)

当然,正确设置所有代理和IB挂钩.

编辑:我只是重读你的问题.回答您问题的示例部分是UIImageView的框架规范及其contentMode设置.