gpt4 book ai didi

swift - UIImagePickerController didFinishPickingMediaWithInfo 没有被cameraOverlyView调用

转载 作者:行者123 更新时间:2023-11-30 10:52:15 60 4
gpt4 key购买 nike

我有带有cameraOverlyView的UIImagePickerController。我向覆盖 View 添加了点击手势识别器 - 当用户点击 View 时,应停止并保存录制:

let mediaUI = UIImagePickerController()
mediaUI.sourceType = sourceType
mediaUI.mediaTypes = [kUTTypeMovie as String]
mediaUI.allowsEditing = true
mediaUI.delegate = self

//customView stuff
let customViewController = CustomOverlayViewController(
nibName:"CustomOverlayViewController",
bundle: nil
)
let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
customView.frame = delegate.view.frame //self.picker.view.frame
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(cameraViewTapped(tapGestureRecognizer:)))
customView.cameraView.addGestureRecognizer(tapGestureRecognizer)
customView.delegate = delegate


delegate.present(mediaUI, animated: true, completion: {
mediaUI.cameraOverlayView = customView
})

手势识别器调用此:

@objc func cameraViewTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
if isRecording {
self.picker!.stopVideoCapture()
self.recordButton.isEnabled = false
print("stopped")
isRecording = false
} else {
self.picker!.startVideoCapture()
print("started")
isRecording = true
}
}

委托(delegate)方法:

extension HomeViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : Any]) {
print("didFinishPickingMediaWithInfo")
dismiss(animated: true, completion: nil)

guard
let mediaType = info[UIImagePickerControllerMediaType] as? String,
mediaType == (kUTTypeMovie as String),
let url = info[UIImagePickerControllerMediaURL] as? URL,
UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.path)
else {
return
}

// Handle a movie capture
UISaveVideoAtPathToSavedPhotosAlbum(
url.path,
self,
#selector(video(_:didFinishSavingWithError:contextInfo:)),
nil)
}

}

我的问题是如何从选择器 Controller 获取录音?由于覆盖 View ,未调用委托(delegate)方法 didFinishPickingMediaWithInfo:UIImagePickerController didFinishPickingMediaWithInfo not being called when cameraOverlyView property is assigned

最佳答案

通过添加以下代码行解决了该问题:

mediaUI.showsCameraControls = false

关于swift - UIImagePickerController didFinishPickingMediaWithInfo 没有被cameraOverlyView调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54332102/

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