gpt4 book ai didi

xcode - 在后台加载 gif 图像?

转载 作者:行者123 更新时间:2023-11-28 09:28:31 24 4
gpt4 key购买 nike

描述/我尝试了什么

我导入了一个库,它可以让我漂亮地将图像异步加载到我的 UITableView (https://github.com/natelyman/SwiftImageLoader) 中。问题是它不支持 gif。所以我做了 case 语句以在需要时独立检索 gif 并使用另一个库显示 gif。

问题

现在的问题是,每当我尝试加载 gif 时,滚动变得非常不稳定。

问题

有人可以帮我解决这个问题吗?它是否涉及将其放在后台线程上?如果是,怎么办?

代码

if let url = NSURL(string: arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString) {

let imageURL = arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString

if (imageURL.lowercaseString.rangeOfString("gif") != nil) {

cell.thumbnail.image = UIImage.animatedImageWithAnimatedGIFURL(url)


} else {

ImageLoader.sharedLoader.imageForUrl(arrayByVotes[indexPath.row].objectForKey("thumbnail") as NSString, completionHandler:{(image: UIImage?, url: String) in

cell.thumbnail.image = image
})

}

}

最佳答案

也许内存中同时有许多 gif 图像会影响滚动的性能。尝试从不可见的单元格中删除图像,并仅在单元格出现时添加图像。一个好的方法是来自 UITableViewDelegate 的 tableView(_:willDisplayCell:forRowAtIndexPath:)

关于xcode - 在后台加载 gif 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29597726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com