【发布时间】:2014-03-26 11:51:34
【问题描述】:
我正在使用自定义 UICollectionViewCell,该单元格包含一个大小为 (320,145) 的 UIImageView,但我需要在其中显示 400 x 400 的图像,因此我尝试使用 UIScrollView 显示整个图像而不裁剪它,即用户可以滚动查看整个图像的部分。
我在 scrollView 中添加了我的 imageView,并为 scrollView 提供了适当的帧大小和内容大小,如下面的代码所示。但是静止图像看起来不正确,我可以看到图像变小以适应屏幕,我可以看到整个图像并滚动也可以,但我想看到完整的图像,即 400 x 400。
UIScrollView * imgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 145)];
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[imgScrollView addSubview:_albumImageView];
[imgScrollView setBackgroundColor:[UIColor yellowColor]];
[imgScrollView setContentSize:CGSizeMake(400, 400)]; /// my _albumImageView is of 400 x 400
_albumImageView.contentMode = UIViewContentModeScaleToFill;
_albumImageView.clipsToBounds = YES;
[self.contentView addSubview:imgScrollView];
以上代码的输出如下图所示
但我希望它如下图所示,启用滚动功能。(相同大小的图像可能不同)
【问题讨论】:
标签: ios iphone uiscrollview uiimageview uiimage