ios - swift 在 UITableViewCell 中播放多个视频依赖于 Scroll

标签 ios swift uitableview video uiscrollview

您好,我正在尝试提出一些申请。

这就是这个应用程序(我无法在 stackoverflow 中上传视频..所以我链接了我的博客并上传了视频)

http://blog.naver.com/cooksunghun/220488172371

喜欢这个应用程序。

tableview中有多个视频。

但是播放视频仅在一个talbleViewCell中

我尝试制作了 tableViewCell 并嵌入视频。但我不能只播放一个部分取决于滚动...(我是编程新手 T_T)

我尝试使用scrollViewDidScroll和VisibleCells

func scrollViewDidScroll(scrollView: UIScrollView) {
    let cell = VideoCell()
    let visibleCell = tableView.visibleCells 
    var count = visibleCell[0]
    switch count {
        case visibleCell[0] : cell.playVideo()
        case visibleCell[1] : print("test2")
        case visibleCell[2] : print("test3")
        case visibleCell[3] : print("test4")
        default : print("testDefault")
    }
}

希望有人给点意见​​。感谢您! (抱歉英语不好) 我在等你的主意!

最佳答案

也许为时已晚,但你走错了路。您不需要 UIScrollViewDelegate 方法,只需要 UITableViewDelegate 中的此方法;

- tableView:willDisplayCell:forRowAtIndexPath:

为了什么?根据苹果文档;

A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

因此,根据滚动方向,当您的下一个单元格准备显示时,此方法将触发,您需要准备要在此方法中播放的视频内容。

- tableView:didEndDisplayingCell:forRowAtIndexPath:

为了什么?根据苹果文档;

Use this method to detect when a cell is removed from a table view, as opposed to monitoring the view itself to see when it appears or disappears.

因此,根据滚动方向,当您最后看到的单元格将准备销毁时。同时,您的下一个单元格将准备显示。您需要准备在此处停止您的视频内容。您没有提供有关视频内容类的任何信息,该类可能是 MPMoviePlayerControllerAVFoundation,因此请搜索如何准备视频内容以停止和播放。

关于ios - swift 在 UITableViewCell 中播放多个视频依赖于 Scroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32696808/

相关文章:

iphone - 如何将关键字#define 生成的常量值作为参数传递给方法?

ios - Swift:如何从其他 View 更改 View 的背景

swift 3 (SpriteKit) : Reseting the GameScene after the game ends

ios - 在页 footer 分创建按钮并检测正确的点击

php - json 解析失败 - cocoa 错误 3840 和字符 0 周围的无效值

ios - UIlabel的文字截断

ios - 如何使用 SDWebImage 从缓存中提取旧的 UIImage 并将其放入占位符?

swift - 动画在 Swift 中完成时调用函数

ios - 当 UITableView 滚动到非顶部并显示索引 2 超出范围 [0..1] 时,它会崩溃

swift - UITableView header UITableViewAutomaticDimension 不工作