gpt4 book ai didi

swift - Fusuma Album View video 拇指交换

转载 作者:行者123 更新时间:2023-11-28 16:05:51 25 4
gpt4 key购买 nike

我将 Fusuma 用于我的图像和视频库。我对滚动画廊 View (FSAlbumView.swift) 有疑问。当我滚动时,它会交换视频缩略图,或者代替视频缩略图出现图像缩略图,图像缩略图没有任何问题,问题仅在于视频缩略图。

这是我的代码。

 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("FSAlbumViewCell", forIndexPath: indexPath) as! FSAlbumViewCell

let currentTag = cell.tag + 1
cell.tag = currentTag

let asset = self.images[indexPath.item] as! PHAsset
if(asset.mediaType == .Image){
self.imageManager?.requestImageForAsset(asset,
targetSize: cellSize,
contentMode: .AspectFill,
options: nil) {
result, info in

if cell.tag == currentTag {
cell.image = result
}

}
}else if(asset.mediaType == .Video){
self.imageManager?.requestAVAssetForVideo(asset, options: nil, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) in
//dispatch_async(dispatch_get_main_queue(), {

let asset = asset as? AVURLAsset
if asset?.URL.absoluteString != nil{
self.videoURLArray.append([indexPath.row:(asset?.URL.absoluteString)!])
}
if cell.tag == currentTag {
cell.video = asset?.URL
// self.videoURLArray[indexPath.row] = (asset?.URL.absoluteString)!
print(asset?.URL)

}
//..var data = NSData(contentsOfURL: asset!.URL)

//})
})
}
return cell
}

最佳答案

我们也遇到了同样的问题。我们所做的是在下面给出。不知道这样对不对。

评论下面的语句。

let currentTag = cell.tag + 1  
cell.tag = currentTag

添加用以下代码片段替换 if-else block

self.imageManager?.requestImageForAsset(asset, targetSize: cellSize, contentMode: .AspectFill, options: nil){
result, info in


if(asset.mediaType == .Video){
self.imageManager?.requestAVAssetForVideo(asset, options: nil, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) in

let asset = asset as? AVURLAsset
if asset?.URL.absoluteString != nil{
self.videoURLArray.append([indexPath.row:(asset?.URL.absoluteString)!])
}
})
}
cell.image = result
}

关于swift - Fusuma Album View video 拇指交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40301792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com