iOS swift 4 imageview under scrollview : double tap to zoom out
iOS swift 4 imageview under scrollview : double tap to zoom out
我已经应用了图像视图来缩放in/out。那很容易。在图像视图上应用双击时,无法检测到 select 方法。
我使用 Xcode 9 和 swift 4 。你能告诉我滚动视图是否应该应用双击手势吗?
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
}
}
来自 UIImageView
的 属性 isUserInteractionEnabled
的 docs。
This class changes the default value of this property to false.
因此,如果您只启用用户交互,您的问题应该可以解决。
imageView.isUserInteractionEnabled = true
如果还是不行。检查是否有其他视图阻止了此视图的触摸。
我已经应用了图像视图来缩放in/out。那很容易。在图像视图上应用双击时,无法检测到 select 方法。
我使用 Xcode 9 和 swift 4 。你能告诉我滚动视图是否应该应用双击手势吗?
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
}
}
来自 UIImageView
的 属性 isUserInteractionEnabled
的 docs。
This class changes the default value of this property to false.
因此,如果您只启用用户交互,您的问题应该可以解决。
imageView.isUserInteractionEnabled = true
如果还是不行。检查是否有其他视图阻止了此视图的触摸。