IOS: add imageview in a scrollview to have zoom

后端 未结 4 1845
走了就别回头了
走了就别回头了 2020-12-02 09:39

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 UIIma

4条回答
  •  再見小時候
    2020-12-02 10:00

    1. Set your view controller up as a
    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.

提交回复
热议问题