我有2MB的GIF文件,但是當我使用celluar和我的高速結束時,我有15kb/s,我必須等待一定的時間才能繼續使用應用程序..Swift 2 - 防止加載大gif文件卡住
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
getGif()
}
func getGif(){
dispatch_async(dispatch_get_main_queue(), {
do{
if let json = try NSJSONSerialization.JSONObjectWithData(NSData(contentsOfURL: NSURL(string: "http://google.bg/gif.php")!)!, options: .MutableContainers) as? NSArray{
self.gifUrl = json[0]["url"] as! String
self.theGif.image = UIImage.gifWithURL(self.gifUrl)
}
}catch{}
})
}
調度不工作...
如何繼續使用應用程序,而圖像加載?
使用NSURLSession下載您的數據。 Starter tip here:http://stackoverflow.com/a/35358750/2227743 – Moritz
與Eric同意,不要使用'NSData'的'contentsOfURL',它會阻塞主線程。 – JAL