【问题标题】:UIImagePickerController didFinishPickingMediaWithInfo not being called with cameraOverlyViewUIImagePickerController didFinishPickingMediaWithInfo 没有被 cameraOverlyView 调用
【发布时间】:2019-01-23 16:54:07
【问题描述】:

我有带有 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

【问题讨论】:

  • 能把用过的方法贴出来
  • 贴出方法

标签: swift uiimagepickercontroller


【解决方案1】:

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

mediaUI.showsCameraControls = false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多