IOS:在scrollview中添加imageview以进行缩放 [英] IOS: add imageview in a scrollview to have zoom
本文介绍了IOS:在scrollview中添加imageview以进行缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置一个带有 UIImage
的UIImageView,并将此imageview放在 UIScrollView
中以获得缩放这个图片;
我想要这个 UIImageView
和 UIScrollView
以适应视图中心的矩形。 。这可能吗?
I want to set a UIImageView with a UIImage
and put this imageview inside a UIScrollView
to obtain a zoom of this image;
and I want this UIImageView
and UIScrollView
to fit in the rect at the center of the view...is it possible?
推荐答案
- 将视图控制器设置为
< UIScrollViewDelegate>
- 绘制
UIScrollView
您想要的矩形中心矩形视图。将检查器中的最大缩放设置为大于1的值。如4或10。 - 右键单击滚动视图并将代理连接到视图控制器。
- 在
UIScrollView
中绘制UIImageView
并使用您想要的任何图像进行设置。使其与UIScrollView
的大小相同。 - Ctrl +拖动表单
UIImageView
到View控制器的.h
,为UIImageView <创建
IBOutlet
/ code>,称之为聪明的东西,如imageView
。 -
添加此代码:
- Set your view controller up as a
<UIScrollViewDelegate>
- Draw your
UIScrollView
the size you want for the rectangle at the center of the view. Set the max zoom in the inspector to something bigger than 1. Like 4 or 10. - Right click on the scroll view and connect the delegate to your view controller.
- Draw your
UIImageView
in theUIScrollView
and set it up with whatever image you want. Make it the same size as theUIScrollView
. - Ctrl + drag form you
UIImageView
to the.h
of your View controller to create anIBOutlet
for theUIImageView
, call it something clever likeimageView
. Add this code:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
运行app并捏并且直到你心中的内容。
Run the app and pinch and pan til your heart's content.
这篇关于IOS:在scrollview中添加imageview以进行缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文