微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 检查表如何查看单元格焦点和播放器设置暂停

my project

我连续几张桌子上有几个视频.

问题是它们是同步播放的.
在屏幕上1video和2video同步播放

如何在表格视图和cell.player上跟踪焦点单元格?.play().和其他细胞cell.player?.pause()

我的代码

class MyViewController
//don't work
func tableView(_ tableView: UITableView,didEnddisplaying cell: UITableViewCell,forRowAt indexPath: IndexPath) {
    if let cell = tableView.cellForRow(at: indexPath) as? ListViewCell {
        cell.player?.pause()
    }
}


//don't call
func tableView(_ tableView: UITableView,didUpdateFocusIn context: UITableViewFocusUpdateContext,with coordinator: UIFocusAnimationCoordinator) {
    print("table view cell didUpdateFocusIn")
}




class MyTableviewCell

override func prepareForReuse() {
        super.prepareForReuse()
        player?.pause()
    }

解决方法

我正在对您的项目进行一些更改.检查一下
https://yadi.sk/d/bQ-eIyMz3VF28V

决定滚动时要播放或暂停的视频:

func handleScroll() {
    if let indexPathsForVisibleRows = myTableView.indexPathsForVisibleRows,indexPathsForVisibleRows.count > 0 {
        var focusCell: ListViewCell?

        for indexPath in indexPathsForVisibleRows {
            if let cell = myTableView.cellForRow(at: indexPath) as? ListViewCell {
                if focusCell == nil {
                    let rect = myTableView.rectForRow(at: indexPath)
                    if myTableView.bounds.contains(rect) {
                        cell.player?.play()
                        focusCell = cell
                    } else {
                        cell.player?.pause()
                    }
                } else {
                    cell.player?.pause()
                }
            }
        }
    }
}

希望这会帮助你.

原文地址:https://www.jb51.cc/iOS/331691.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐