SwiftGif
SwiftGif copied to clipboard
Laggy TableView scroll.
Hi, I created a custom UITableViewCell with UIImageView inside to display the gifs in a TableView, but scrolling the TableView is slow, laggy and get stuck for a few seconds while trying to scroll. What can I do? Thanks.
Same issue. Did you ever figure it out?
This is a conceptual problem with this UIImage
extension when creating a GIF from data.
The composition of an image from data can be quite time intensive and hence should happen on a background thread, not on main
. You can do this the following way:
DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async {
let image = UIImage.gif(data: data)
DispatchQueue.main.async {
imageView.image = image
}
}
However, this will cause a flicker due to a lag in displaying the image when the table view's cells are reloaded, e.g. with tableView.reloadData()
.
Neither seems really acceptable for a good UI.