iphone uiscrollview 和 uiimageview - 设置初始缩放
我使用以下代码将图像加载到滚动视图中。图像始终以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
仅当您实现 viewForZoomingInScrollView: 委托回调时,缩放才有效。
Zooming only works when you implement the
viewForZoomingInScrollView:
delegate callback.我想通了...我正在使用scrollView.zoomScale = 0.37;在加载图像之前更改了代码并且效果很好。
I figured it out... I was using scrollView.zoomScale = 0.37; before I loaded the image changed code and it works great.
有一个
zoomScale
属性。There is a
zoomScale
property that you can set.我面临着同样的问题..
我使用内置方法: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
您必须在视图出现时设置初始缩放,而不是在视图加载时设置初始缩放,因为它太有效了。
You must set the initial zoom when the viewwillappear and not when the viewdidload for it too work.