Explorar el Código

viewDidAppear时collectionCell未创建完成fixed

Chris hace 5 años
padre
commit
4ee5edd6ff

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityVideoCoverCollectionCell.swift

@@ -697,7 +697,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
     
     // MARK: - 播放动作
     func play() {
-        playStatusImageView.isHidden = true
+        playStatusImageView.isHidden = true        
         videoPlayView.play()
     }
     

+ 9 - 7
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/ViewController/CommunityVideoListController.swift

@@ -256,7 +256,7 @@ extension CommunityVideoListController: UICollectionViewDelegateFlowLayout,UICol
 // MARK: -
 extension CommunityVideoListController {
     
-    func startPlay(_ cell: CommunityVideoCoverCollectionCell?) {
+    func startPlay(_ cell: CommunityVideoCoverCollectionCell?) {        
         cell?.play()
     }
     
@@ -267,12 +267,14 @@ extension CommunityVideoListController {
     }
     
     func playFirstVideoWhenViewDidAppeared() {
-        let showCells = collectionView.visibleCells
-        for tmpCell in showCells {
-            let videoCell = tmpCell as? CommunityVideoCoverCollectionCell
-            startPlay(videoCell)
-            prePlayCell = videoCell
-            break
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(0.2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { () -> Void in
+            let showCells = self.collectionView.visibleCells
+            for tmpCell in showCells {
+                let videoCell = tmpCell as? CommunityVideoCoverCollectionCell
+                self.startPlay(videoCell)
+                self.prePlayCell = videoCell
+                break
+            }
         }
     }