Skip to content

Commit

Permalink
Remove layer content when image set to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Jan 31, 2017
1 parent 08777da commit b9351df
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions APNGKit/APNGImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ open class APNGImageView: UIView {
let animating = isAnimating
stopAnimating()

image?.reset()
guard let image = image else {
updateContents(nil)
return
}

if let frame = image?.next(currentIndex: currentFrameIndex) {
currentFrameDuration = frame.duration
updateContents(frame.image)

if animating {
startAnimating()
}

if autoStartAnimation {
startAnimating()
}
image.reset()

let frame = image.next(currentIndex: currentFrameIndex)
currentFrameDuration = frame.duration
updateContents(frame.image)

if animating {
startAnimating()
}

if autoStartAnimation {
startAnimating()
}
}
}
Expand Down Expand Up @@ -212,6 +216,9 @@ open class APNGImageView: UIView {

delegate?.apngImageView?(self, didFinishPlaybackForRepeatedCount: repeated)

// If user set image to `nil`, do not render anymore.
guard let _ = self.image else { return }

currentFrameIndex = 0
repeated = repeated + 1

Expand All @@ -230,6 +237,7 @@ open class APNGImageView: UIView {
}

currentPassedDuration = currentPassedDuration - currentFrameDuration

let frame = image.next(currentIndex: currentFrameIndex)
currentFrameDuration = frame.duration
updateContents(frame.image)
Expand Down

0 comments on commit b9351df

Please sign in to comment.