问题
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
    }
}
回答1:
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.
来源:https://stackoverflow.com/questions/52226161/ios-swift-4-imageview-under-scrollview-double-tap-to-zoom-out