Как я могу назначить делегата для UIVideoEditorController в ReactNative, когда модуль, над которым я работаю, это просто классы - PullRequest
0 голосов
/ 14 сентября 2018
    func previewRecording (withFileName fileURL: String) {
        if UIVideoEditorController.canEditVideo(atPath: fileURL) {
            let rootView = UIApplication.getTopMostViewController()
            let editController = UIVideoEditorController()
            editController.videoPath = fileURL
//            editController.delegate = ?????
            rootView?.present(editController, animated: true, completion: nil)
        } else {

        }
    }

^ текущий код

Я ходил по Интернету кругами несколько раз, пытаясь понять это.Каков наилучший подход для указания делегата для UIVideoEditorController здесь?Это встроенный модуль, в котором нет ViewController, только служебные классы.

Простой пример кода, с которым я столкнулся

extension SomeViewController : 
    UIVideoEditorControllerDelegate, 
    UINavigationControllerDelegate {

  func videoEditorController(_ editor: UIVideoEditorController, 
    didSaveEditedVideoToPath editedVideoPath: String) {

    print("saved!")
  }
}

Я просто растерялся из-за того, как этого добитьсяв моем модуле, хотя.

1 Ответ

0 голосов
/ 15 сентября 2018
    @objc class ScreenRecordCoordinator: NSObject
    {
        let previewDelegateView = PreviewDelegateView()
        // .......
        editController.delegate = previewDelegateView
    }

    class PreviewDelegateView: UIViewController, UINavigationControllerDelegate, UIVideoEditorControllerDelegate {

        var isSaved:Bool = false

        func videoEditorController(_ editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
            print("save called")
            if(!self.isSaved) {
                self.isSaved = true
                print("trimmed video saved!")
                editor.dismiss(animated: true, completion: {
                ReplayFileUtil.replaceItem(at: URL(fileURLWithPath: editor.videoPath), with: URL(fileURLWithPath: editedVideoPath))
                    self.isSaved = false
                })
            }
        }
    }
...