首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何呈现UIVideoEditorController

如何呈现UIVideoEditorController
EN

Stack Overflow用户
提问于 2017-07-23 00:07:02
回答 1查看 4.3K关注 0票数 5

我从来没有使用过UIVideoEditorController,所以我不知道从哪里开始。

当用户在我的集合视图单元格中选择视频时,我希望视图控制器弹出。

我已经知道了视频的URL,所以我只需要有人告诉我如何正确地呈现视图控制器。

到目前为止,这是我的代码

代码语言:javascript
复制
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let video = videosArray[indexPath.row]

视频变量是我想让他们编辑的视频。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-23 05:02:24

试试这个:

代码语言:javascript
复制
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let video = videosArray[indexPath.row] // videosArray is a list of URL instances
    if UIVideoEditorController.canEditVideo(atPath: video.path) {
        let editController = UIVideoEditorController()
        editController.videoPath = video.path
        editController.delegate = self
        present(editController, animated:true)
    }
}

此外,您还需要添加UIVideoEditorControllerDelegate方法来删除显示的视频编辑器控制器:

代码语言:javascript
复制
extension YourViewController: UIVideoEditorControllerDelegate {
    func videoEditorController(_ editor: UIVideoEditorController, 
       didSaveEditedVideoToPath editedVideoPath: String) {
       dismiss(animated:true)
    }

    func videoEditorControllerDidCancel(_ editor: UIVideoEditorController) {
       dismiss(animated:true)
    }

    func videoEditorController(_ editor: UIVideoEditorController, 
               didFailWithError error: Error) {
       print("an error occurred: \(error.localizedDescription)")
       dismiss(animated:true)
    }
}
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45260431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档