IOS:在滚动视图中添加图像视图以进行缩放

IOS: add imageview in a scrollview to have zoom(IOS:在滚动视图中添加图像视图以进行缩放)
本文介绍了IOS:在滚动视图中添加图像视图以进行缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想用 UIImage 设置 UIImageView 并将这个 imageview 放在 UIScrollView 中以获得这个图像的缩放;我希望这个 UIImageViewUIScrollView 适合视图中心的矩形...有可能吗?

解决方案

  1. 将您的视图控制器设置为 <UIScrollViewDelegate>
  2. UIScrollView 绘制为视图中心矩形所需的大小.将检查器中的最大缩放设置为大于 1 的值.例如 4 或 10.
  3. 右键单击滚动视图并将代理连接到您的视图控制器.
  4. UIScrollView 中绘制您的 UIImageView 并使用您想要的任何图像进行设置.使其与 UIScrollView 的大小相同.
  5. Ctrl + 将 UIImageView 拖动到 View 控制器的 .h 中,为 UIImageView 创建一个 IBOutletcode>,把它称为 imageView 之类的聪明东西.
  6. 添加此代码:

    <块引用>

    -(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView{返回self.imageView;}

  7. 运行应用程序并捏合和平移,直到心满意足.

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?

解决方案

  1. Set your view controller up as a <UIScrollViewDelegate>
  2. 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.
  3. Right click on the scroll view and connect the delegate to your view controller.
  4. Draw your UIImageView in the UIScrollView and set it up with whatever image you want. Make it the same size as the UIScrollView.
  5. Ctrl + drag form you UIImageView to the .h of your View controller to create an IBOutlet for the UIImageView, call it something clever like imageView.
  6. Add this code:

    -(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
        return self.imageView;
    }
    

  7. Run the app and pinch and pan til your heart's content.

这篇关于IOS:在滚动视图中添加图像视图以进行缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)