我有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