我正在尝试将UITapGestureRecogniser添加到我为UIImagePickerController创建的覆盖视图中。但是没有检测到水龙头。以下是我的代码:
//Setting up image picker controller
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.showsCameraControls = false
//Setting up the tap gesture
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.cropImageAroundTap(sender:)))
tapGesture.delegate = self
//Setting up overlay view
let overlayView = UIView.init(frame: self.view.frame)
overlayView.isOpaque = false
overlayView.isUserInteractionEnabled = true
overlayView.backgroundColor = UIColor.clear
overlayView.addGestureRecognizer(tapGesture)
imagePicker.cameraOverlayView = overlayView
self.present(imagePicker, animated: true, completion: nil )
如果我将手势识别器添加到imagePicker.view,那么相机控制的部分会检测水龙头而不是预览窗口。以下是我检测水龙头的功能:
func cropImageAroundTap(sender: UITapGestureRecognizer) {
if sender.state == .ended {
NSLog("hello")
}
}
有没有办法检测预览窗口上的点击?
答案 0 :(得分:0)
我能够在图像选择器的预览视图中检测到轻击手势,而不是设置:
imagePicker.cameraOverlayView = overlayView
我将overlayView添加为imagePicker的子视图
imagePicker.view.addSubview(overlayView)