gpt4 book ai didi

ScrollView 下的iOS swift 4 imageview : double tap to zoom out

转载 作者:可可西里 更新时间:2023-11-01 01:56:50 29 4
gpt4 key购买 nike

我已经应用 ImageView 通过捏合来放大/缩小。那很容易。在 ImageView 上应用双击时,无法检测到选择方法。

我使用 Xcode 9 和 swift 4 。你能告诉我 ScrollView 是否应该应用双击手势吗?

 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
}
}

最佳答案

来自docs UIImageView 的属性 isUserInteractionEnabled

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

因此,如果您只启用用户交互,您的问题应该得到解决。

imageView.isUserInteractionEnabled = true

如果还是不行。检查是否有其他 View 阻止了此 View 的触摸。

关于 ScrollView 下的iOS swift 4 imageview : double tap to zoom out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52226161/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com