2017-03-09 47 views
0

我使用BSImagePicker圖像選取器控制器()轉換PHAsset到的UIImage並顯示用戶

圖像拾取控制器返回PHAsset而不是UIImage的,所以我發現瞭如何PHAsset轉換的UIImage使用此功能:

PHAsset to UIImage

func getAssetThumbnail(asset: PHAsset) -> UIImage { 
    let manager = PHImageManager.default() 
    let option = PHImageRequestOptions() 
    var thumbnail = UIImage() 
    option.isSynchronous = true 
    manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in 
     thumbnail = result! 
    }) 
    return thumbnail 
} 

問題是,我想回到的PHImageManagerMaximumSize的的targetSize。 Althought發生這種情況時,我得到一個errorr This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

當我設置targetSizeCGSize(width: 100, height: 100)

回答

0

只是你需要做的,以避免你的錯誤是迫使應用程序在修改自動佈局不發生錯誤主線程。例如,您可以在設置圖像時在主隊列中使用調度程序。 例如:

let image = self.getAssetThumbnail(asset: <YourPHAsset>) 

     DispatchQueue.main.async { 

      self.imageView.image = image 
     } 

當您使用targetSize ...怪也應該發生的錯誤...