我希望有人可以帮助我。我试图允许用户捏UIImageView(允许最大和最小级别)上的缩放。但是由于某种原因,它无法正常工作。图像会稍微放大,然后反弹。谢谢。

这是变焦功能

func zoom(sender:UIPinchGestureRecognizer) {


    if sender.state == .Ended || sender.state == .Changed {

        let currentScale = self.view.frame.size.width / self.view.bounds.size.width
        var newScale = currentScale*sender.scale

        if newScale < 1 {
            newScale = 1
        }
        if newScale > 9 {
            newScale = 9
        }

        let transform = CGAffineTransformMakeScale(newScale, newScale)

        self.imageView?.transform = transform
        sender.scale = 1

    }

}

最佳答案

UIImageView用UIScrollView捏缩放swift 3和Xcode 8字母缩放ios中的图像缩放ios
在 Storyboard 中设置uiscrollview委托(delegate)
Youtube video URL

 class PhotoDetailViewController: UIViewController, UIScrollViewDelegate {

    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var imgPhoto: UIImageView!

    override func viewDidLoad() {

        super.viewDidLoad()

        scrollView.minimumZoomScale = 1.0
        scrollView.maximumZoomScale = 6.0
        // scrollView.delegate = self - it is set on the storyboard.
    }

    func viewForZooming(in scrollView: UIScrollView) -> UIView? {

        return imgPhoto
    }

10-08 08:51