UIImageView pinch zoom swift

前端 未结 13 784
误落风尘
误落风尘 2020-11-28 04:06

I was hoping someone could help me out. I am trying to allow a user to pinch zoom on a UIImageView(with a max and min level allowed). But for some reason the it does not wor

13条回答
  •  一个人的身影
    2020-11-28 04:51

    Swift 3 solution

    This is the code I used. I added imageView to scrollView as a subview.

    class ZoomViewController: UIViewController,UIScrollViewDelegate {
    
    @IBOutlet weak var scrollView:UIScrollView!
    @IBOutlet weak var imageView:UIImageView!
    
    override func viewDidLoad() {
    
            super.viewDidLoad()
            scrollView.delegate = self
    
            scrollView.minimumZoomScale = 1.0
            scrollView.maximumZoomScale = 10.0//maximum zoom scale you want
            scrollView.zoomScale = 1.0
    
    }
    
    func viewForZooming(in scrollView: UIScrollView) -> UIView? {
            return imageView
    }
    

提交回复
热议问题