IOS: add imageview in a scrollview to have zoom(IOS:在滚动视图中添加图像视图以进行缩放)
本文介绍了IOS:在滚动视图中添加图像视图以进行缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 UIImage 设置 UIImageView 并将这个 imageview 放在 UIScrollView 中以获得这个图像的缩放;我希望这个 UIImageView 和 UIScrollView 适合视图中心的矩形...有可能吗?
解决方案
- 将您的视图控制器设置为
<UIScrollViewDelegate> - 将
UIScrollView绘制为视图中心矩形所需的大小.将检查器中的最大缩放设置为大于 1 的值.例如 4 或 10. - 右键单击滚动视图并将代理连接到您的视图控制器.
- 在
UIScrollView中绘制您的UIImageView并使用您想要的任何图像进行设置.使其与UIScrollView的大小相同. - Ctrl + 将
UIImageView拖动到 View 控制器的.h中,为UIImageView创建一个IBOutletcode>,把它称为imageView之类的聪明东西. 添加此代码:
<块引用>-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView{返回self.imageView;}运行应用程序并捏合和平移,直到心满意足.
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?
解决方案
- Set your view controller up as a
<UIScrollViewDelegate> - Draw your
UIScrollViewthe 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
UIImageViewin theUIScrollViewand set it up with whatever image you want. Make it the same size as theUIScrollView. - Ctrl + drag form you
UIImageViewto the.hof your View controller to create anIBOutletfor theUIImageView, call it something clever likeimageView. Add this code:
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; }Run the app and pinch and pan til your heart's content.
这篇关于IOS:在滚动视图中添加图像视图以进行缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:IOS:在滚动视图中添加图像视图以进行缩放
基础教程推荐
猜你喜欢
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
