2015-09-28 55 views
0

我知道這一點:如何僅用一個UIImageView顯示相冊中的所有照片?

imageView.image = aImage 

現在我想告訴很多照片,即,在相冊中的所有照片。

let fetchResult = PHAsset.fetchAssetsWithLocalIdentifiers(Array(photoIDSet), options: nil) 
let imageRequestOptions = PHImageRequestOptions() 
imageRequestOptions.synchronous = true 
imageRequestOptions.resizeMode = .Fast 

fetchResult.enumerateObjectsUsingBlock({ 
    fetchedObject, _, _ in 
    if let asset = fetchedObject as? PHAsset{ 
     PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: specialSize, contentMode: .AspectFit, options: imageRequestOptions, resultHandler: { 
      image, _ in 
      dispatch_async(dispatch_get_main_queue(), { 
       imageView.image = image 
      }) 
     }) 
    } 
}) 

上述代碼無法按預期方式工作。如果幸運的話,它只會改變一次。

有沒有辦法?

+0

創建資產數組。從資產中逐一獲取圖像,並通過在兩張圖像之間保持1秒的延遲來顯示圖像。 – Leena

回答

0

我發現這個問題。整個enumerateObjectsUsingBlock()方法運行在一個runloop中,當enumerate方法用完時,它只對imageView(最後一個圖像)提交一個更改。

如何解決?使用- performSelector:withObject:afterDelay:在函數結束時調用函數self。請記住退出。

相關問題