如何缩小 UIScrollView 中的图像而不被剪切?

发布于 2024-12-05 00:20:33 字数 775 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡渣熟男 2024-12-12 00:20:33

没有看到代码,不清楚,但也许它只是剪切图像?

thescrolview.clipsToBounds = NO;

Without seeing the code it's not clear but perhaps its just clipping the image?

thescrolview.clipsToBounds = NO;
转角预定愛 2024-12-12 00:20:33

将委托设置为scrollView并将imageView返回到缩放/缩放

  • (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    // 返回我们想要缩放的视图
    返回vw图像;
    }

Set the delegate to scrollView and return the imageView to scale/zoom

  • (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    // Return the view that we want to zoom
    return vwImage;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文