How to load animated GIF from photo library

后端 未结 1 1615
情书的邮戳
情书的邮戳 2020-12-14 13:30

In iOS Swift I\'m having difficulty loading an animated GIF from the device photo library to a UIImageView or creating a .gif file from it. I have no problem displaying the

相关标签:
1条回答
  • 2020-12-14 13:49

    Yes, Use ALAssetsLibrary → now called PHAsset.

    You should get the NSData of the gif, not UIImage( because UIImage will only get the first frame.)

    So basically you would do something like this:

    One you get the asset

    let requestOptions = PHImageRequestOptions()
    requestOptions.isSynchronous = true // adjust the parameters as you wish    
    
    PHImageManager.default().requestImageData(for: asset, options: requestOptions, resultHandler: { (imageData, UTI, _, _) in
        if let uti = UTI,let data = imageData ,
            // you can also use UTI to make sure it's a gif
           UTTypeConformsTo(uti as CFString, kUTTypeGIF) {
            // save data here
        }
    })      
    

    Resource: PHAsset

    0 讨论(0)
提交回复
热议问题