UICollectionViewCell中的AVPlayerViewController错误?

在我的UICollectionView中,我有一个单元格。 这是我的cellForItemAtIndexPath

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellVideo", forIndexPath: indexPath) as? CollectionViewCell let post = self.arrayOfDetails[indexPath.row] var myUrl = post.image // post.image is image url let fileUrl = NSURL(string: post.image) aPlayer = AVPlayer(URL: fileUrl) moviePlayerController.player = aPlayer moviePlayerController.view.frame = CGRectMake(8, 8, videoCell!.frame.size.width-16, 310) moviePlayerController.videoGravity = AVLayerVideoGravityResizeAspectFill moviePlayerController.view.sizeToFit() moviePlayerController.showsPlaybackControls = true videoCell!.addSubview(moviePlayerController.view) return videoCell! } 

问题是AVPlayerViewController不出现在每个单元格上。 但只有在我看的那个单元格下,所以如果我在我的UICollectionView中向下滚动,并且一旦一个新的单元格出现在屏幕上,AVPlayerViewController是在该单元格上,而不是屏幕中间的单元格。 任何build议我可能在这里错了什么?

video在这里: https : //vid.me/e/fU5X

你需要一个新的aPlayer和moviePlayerController为每一个有video的单元格。 像这样的东西应该这样做:

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellVideo", forIndexPath: indexPath) as? CollectionViewCell var aPlayer = AVPlayer() let moviePlayerController = AVPlayerViewController() let post = self.arrayOfDetails[indexPath.row] var myUrl = post.image // post.image is image url let fileUrl = NSURL(string: post.image) var aPlayer = AVPlayer() let moviePlayerController = AVPlayerViewController() aPlayer = AVPlayer(URL: fileUrl) moviePlayerController.player = aPlayer moviePlayerController.view.frame = CGRectMake(8, 8, videoCell!.frame.size.width-16, 310) moviePlayerController.videoGravity = AVLayerVideoGravityResizeAspectFill moviePlayerController.view.sizeToFit() moviePlayerController.showsPlaybackControls = true videoCell!.addSubview(moviePlayerController.view) return videoCell! }