2016-03-18 5 views
0

this guyGifクラスを使用してGif UIImageを作成しています。これでhttps://github.com/mayoff/uiimage-from-animated-gifUIImage Gifローディングデリゲート?

ロードは:

let fileUrl = NSURL(string: "some url" as! String) 
let Gif = UIImage.animatedImageWithAnimatedGIFURL(fileUrl!) 
imageview.image=Gif 

事は、あなたが画像を見るまで、それは7秒のように、多くの時間を時間を要するということです。

私はそれを何らかの方法で事前ロードしたい、またはロードが完了したときに少なくともデリゲートを取得します。

ここには何がありますか?

答えて

1

Grand Central Dispatch(またはGCD)を使用して、バックグラウンドでこのタスクを実行できます。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { 
    // This will happen in the background 
    let fileUrl = NSURL(string: "some url" as! String) 
    let gif = UIImage.animatedImageWithAnimatedGIFURL(fileUrl!) 

    dispatch_async(dispatch_get_main_queue()) { 
     // Always update UI on the main thread 
     imageview.image = gif 
    } 
} 

これはまだそれがGIFをロードするのにかかるしかし時間がかかりますが、ユーザがGIFのロード中に物事を行うことができますので、それは、UIをロックしません。