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

ぃ、小莉子 提交于 2019-12-24 04:39:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!