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()
                }
            }
        }
    }
}

希望这会帮助你.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...