Skip to content

Commit

Permalink
Merge pull request #33 from onevcat/fix/setting-nil
Browse files Browse the repository at this point in the history
Remove layer content when image set to nil
  • Loading branch information
onevcat authored Jan 31, 2017
2 parents 08777da + b9351df commit b754f36
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 b754f36

Please sign in to comment.