我有带cameraOverlyView的UIImagePickerController。我在叠加视图中添加了点击手势识别器-当用户点击视图时,应停止并保存记录:
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
}
}
代理方法:
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)
}
}
我的问题是如何从选择器控制器获取记录?由于存在重叠视图,未调用委托方法didFinishPickingMediaWithInfo:UIImagePickerController didFinishPickingMediaWithInfo not being called when cameraOverlyView property is assigned
答案 0 :(得分:0)
通过添加以下代码行解决了该问题:
this.loadData()