SwiftGif icon indicating copy to clipboard operation
SwiftGif copied to clipboard

Laggy TableView scroll.

Open lorenzoferrante opened this issue 8 years ago • 2 comments

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.

lorenzoferrante avatar Nov 05 '16 12:11 lorenzoferrante

Same issue. Did you ever figure it out?

davidkc0 avatar Jan 17 '17 06:01 davidkc0

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.

mtrezza avatar Nov 17 '17 12:11 mtrezza