PreLoad UICollectionViewCells-快速-以编程方式

问题描述

我的UIView中有一个CollectionView,最多可显示6个单元格。

这些单元格使用我在数据源方法中传递的网址显示视频,如下所示:

func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
    let videoCell = collectionView.dequeueReusableCell(withReuseIdentifier: videoCellIdentifier,for: indexPath) as! VideoCollectionViewCell
    
    
    videoCell.urlPassed = arrayUrls[indexPath.item]
    return videoCell
    
}

为完整起见,我还添加UICollectionViewCell代码

class VideoCollectionViewCell : UICollectionViewCell{

var videoNode = ASVideoNode()

var asset : AVAsset?

var urlPassed : URL?{
    didSet{
            asset = AVAsset(url: self.urlPassed!)
            videoNode.asset = self.asset
            videoNode.gravity = AVLayerVideoGravity.resizeAspectFill.rawValue
            videoNode.shouldAutoplay = true
            videoNode.shouldAutorepeat = true
            videoNode.muted = true
            videoNode.delegate = self
            videoNode.play()
        
    }
}



override init(frame: CGRect) {
    super.init(frame: frame)

    setUpUI()
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}


fileprivate func setUpUI(){

    self.backgroundColor = .red

    addSubnode(videoNode)
    videoNode.view.fillSuperview()
}
}

问题在于,只有在我滚动查看它们时才加载collectionViewCells,因此它们需要花费一些时间才能从传递的网址中获取并播放视频。

是否可以预加载所有单元格,以便用户无需等待每个视频都被提取显示

我已经在网上搜索过,但我发现困难的实现方式对我来说毫无意义,如果您能帮助我,将不胜感激

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)