如何缩小 UIScrollView 中的图像而不被剪切?
我有一个 UIScrollView 占据主视图控制器视图的整个大小。在 viewDidLoad 中,我将具有 600 x 600 图像的 UIView(注意这是在 iPhone 上,而不是 iPad 上)添加到 UIScrollView,并将 UIScrollView 的内容大小设置为 600 x 600,将最小缩放比例设置为 0.5。但是,当我缩小(使用捏合手势)时,视图会缩小,但仅显示最初可见的图像部分 (320 x 430);视图的其余部分是空白的。
当我缩小时,如何让图像填充视图(或者,如果缩小得足够远,则显示整个图像)?
代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *theImage = [UIImage imageNamed:@"Image600x600.png"];
UIImageView *vwImage = [[UIImageView alloc] initWithImage:theImage];
[theScrollView addSubview:vwImage];
[theScrollView setContentSize:CGSizeMake(vwImage.bounds.size.width, vwImage.bounds.size.height)];
[theScrollView setBounces:NO];
[vwImage release];
[theScrollView setMaximumZoomScale:5.0];
[theScrollView setMinimumZoomScale:0.5];
}
I have a UIScrollView that takes up the entire size of the main View Controller's view. In viewDidLoad, I add a UIView with a 600 x 600 image (note this is on an iPhone, not an iPad) to the UIScrollView, and set the UIScrollView's content size to 600 x 600 and the minimum zoom scale to 0.5. However, when I zoom out (with a pinch gesture), the view zooms out, but only the part of the image that was initially visible (320 x 430) appears; the rest of the view is blank.
How can I get the image to fill the view (or, if it's zoomed out far enough, get the entire image to appear) when I zoom out?
code is:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *theImage = [UIImage imageNamed:@"Image600x600.png"];
UIImageView *vwImage = [[UIImageView alloc] initWithImage:theImage];
[theScrollView addSubview:vwImage];
[theScrollView setContentSize:CGSizeMake(vwImage.bounds.size.width, vwImage.bounds.size.height)];
[theScrollView setBounces:NO];
[vwImage release];
[theScrollView setMaximumZoomScale:5.0];
[theScrollView setMinimumZoomScale:0.5];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有看到代码,不清楚,但也许它只是剪切图像?
Without seeing the code it's not clear but perhaps its just clipping the image?
将委托设置为scrollView并将imageView返回到缩放/缩放
// 返回我们想要缩放的视图
返回vw图像;
}
Set the delegate to scrollView and return the imageView to scale/zoom
// Return the view that we want to zoom
return vwImage;
}