gpt4 book ai didi

ios - 如何在 ImagePickerController() 的覆盖 View 上识别 TapGesture ?

转载 作者:行者123 更新时间:2023-11-30 12:38:23 24 4
gpt4 key购买 nike

我正在尝试将 UITapGestureRecogniser 添加到我为 UIImagePickerController 创建的覆盖 View 中。但是没有检测到任何点击。以下是我的代码:

 //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")
}

}

有没有办法检测预览窗口上的点击?

最佳答案

我能够在图像选择器的预览 View 中检测点击手势,而不是设置:

 imagePicker.cameraOverlayView = overlayView

我将overlayView添加为imagePicker的 subview

 imagePicker.view.addSubview(overlayView)

关于ios - 如何在 ImagePickerController() 的覆盖 View 上识别 TapGesture ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42576377/

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