简体   繁体   中英

iOS swift 4 imageview under scrollview : double tap to zoom out

I have already applied the image view to zoom in/out by pinch. That is easy. When it comes to applying double taps on the image view, the select method cannot be detected.

I use Xcode 9 and swift 4 . Would you please tell me whether scrollview should apply the double tap gesture instead ?

 var previewImage : UIImage? = nil


    override func viewDidLoad() {
        super.viewDidLoad()

        scrollView.minimumZoomScale = 1.0
        scrollView.maximumZoomScale = 6.0
        imageView.image = previewImage

        let doubleTap =  UITapGestureRecognizer.init(target: self, action: #selector(self.sampleTapGestureTapped(recognizer:)))
        doubleTap.numberOfTapsRequired = 2
        imageView.addGestureRecognizer(doubleTap)
        // Do any additional setu p after loading the view.
    } 

    @objc func sampleTapGestureTapped(recognizer: UITapGestureRecognizer) {
        print("Tapping working")
    }


}

extension PhotoReviewController: UIScrollViewDelegate {

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

        return imageView
    }
}

From the docs of UIImageView 's property isUserInteractionEnabled .

This class changes the default value of this property to false.

So your problem should be solved if you just enable user interaction.

imageView.isUserInteractionEnabled = true

If it is still not working. Check if some other view is blocking this view's touch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM