Как я могу назначить делегата для UIVideoEditorController в ReactNative, когда модуль, над которым я работаю, это просто классы
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 ответ
@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
})
}
}
}