wangjwchn / AImage

An animated gif & apng engine for iOS in Swift. Have a great performance on memory and cpu usage.
993 stars 93 forks source link

Refactor to UIImageView: #34

Closed Alex601t closed 6 years ago

Alex601t commented 6 years ago

Hey! I like this solution for rendering gifs, but I can't use it in UITable- or CollectionView. Reasons:

  1. UIView doesn't support content mode for scaling images. (https://github.com/wangjwchn/AImage/issues/29)
  2. We can't clear cache or view (because image is drawn on view) when prepare for reuse func is called in UITable- or UICollectionCell.

File changes:

  1. Declare clear function to public, for clear cache and data when using UITable- or CollectionView;
  2. Time fired function;
  3. Decode image.
wangjwchn commented 6 years ago

Hi @Alex601t ,thanks for you contribution 👍 I noticed that you change the function decodeImage, and I think that isn't a good idea. I've tried your version, but it seems that the image can't be decoded in asynchronously that way. You can use the measurement tools in Xcode to verify this. As you can see in the benchmark that I ran them before, if the image is decoded asynchronously. The CPU usage of main thread will be very low. But I can't see the same result if I use your version.

Alex601t commented 6 years ago

@wangjwchn ohhh noo... I have missed one case: in old implementation we set next frame to the layer's contents:self.layer.contents = self.nextFrame?.cgImage, in this PR we are setting layer and image and as a result we are setting image context twice.

I will close this PR and create a new one later.