iphone uiscrollview 和 uiimageview - 设置初始缩放

发布于 2024-08-29 17:17:11 字数 580 浏览 5 评论 0原文

我使用以下代码将图像加载到滚动视图中。图像始终以 100% 缩放比例加载。有没有办法将其设置为加载到另一个缩放级别,例如 0.37?

我尝试过scrollView.zoomScale = .37但它似乎不起作用

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
        self.imageView = tempImage;

        scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
        scrollView.maximumZoomScale = 1;
        scrollView.minimumZoomScale = .37;
        scrollView.clipsToBounds = YES;
        scrollView.delegate = self;

        [scrollView addSubview:imageView];

I use the following code to load an image into an scroll view. The image always loads at 100% zoom. Is there a way to set it to load to another zoom level, say .37?

I have tried scrollView.zoomScale = .37 but it didnt seem to work

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
        self.imageView = tempImage;

        scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
        scrollView.maximumZoomScale = 1;
        scrollView.minimumZoomScale = .37;
        scrollView.clipsToBounds = YES;
        scrollView.delegate = self;

        [scrollView addSubview:imageView];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

—━☆沉默づ 2024-09-05 17:17:11

仅当您实现 viewForZoomingInScrollView: 委托回调时,缩放才有效。

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
  return imageView;
}

Zooming only works when you implement the viewForZoomingInScrollView: delegate callback.

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
  return imageView;
}
寒尘 2024-09-05 17:17:11

我想通了...我正在使用scrollView.zoomScale = 0.37;在加载图像之前更改了代码并且效果很好。

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
self.imageView = tempImage;

scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .37;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .37;

I figured it out... I was using scrollView.zoomScale = 0.37; before I loaded the image changed code and it works great.

UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]];
self.imageView = tempImage;

scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
scrollView.maximumZoomScale = 1;
scrollView.minimumZoomScale = .37;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
scrollView.zoomScale = .37;
胡大本事 2024-09-05 17:17:11

有一个 zoomScale 属性

There is a zoomScale property that you can set.

末骤雨初歇 2024-09-05 17:17:11

我面临着同样的问题..
我使用内置方法:scrollViewForImage

这会将初始缩放设置为级别 5

[self.scrollViewForImage setZoomScale:5animated:YES];

最小缩放级别代码

self.scrollViewForImage.minimumZoomScale=1;

最大缩放级别代码

self.scrollViewForImage.maximumZoomScale=12.0;

希望这会有所帮助

I was facing same issue..
i used the built in method : scrollViewForImage

This will set the initial zoom to level 5

[self.scrollViewForImage setZoomScale:5 animated:YES];

code for minimum zoom level

self.scrollViewForImage.minimumZoomScale=1;

code for Maximum Zoom Level

self.scrollViewForImage.maximumZoomScale=12.0;

Hope this will help

乖乖哒 2024-09-05 17:17:11

您必须在视图出现时设置初始缩放,而不是在视图加载时设置初始缩放,因为它太有效了。

You must set the initial zoom when the viewwillappear and not when the viewdidload for it too work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文