Fusuma Album View video 拇指交换
Fusuma Album View video thumbs swaping
我将 Fusuma 用于我的图片和视频库。
我对滚动画廊视图 (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 块
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
}
我将 Fusuma 用于我的图片和视频库。 我对滚动画廊视图 (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 块
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
}