Skip to content

Commit

Permalink
Merge pull request #97 from onevcat/fix/reset-image-from-stop
Browse files Browse the repository at this point in the history
Reset frame content when start the image view again from stop
  • Loading branch information
onevcat authored Mar 8, 2020
2 parents fd53084 + cffd39b commit df003ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions APNGKit/APNGImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ open class APNGImage: NSObject { // For ObjC compatibility
}
}

// Strong refrence to another APNG to hold data if this image object is retrieved from cache
// Strong reference to another APNG to hold data if this image object is retrieved from cache
// The frames data will not be changed once a frame is setup.
// So we could share the bytes in it between two "same" APNG image objects.
fileprivate let dataOwner: APNGImage?
Expand Down Expand Up @@ -129,7 +129,7 @@ open class APNGImage: NSObject { // For ObjC compatibility
self.disassembler = nil
}

// Init from a disaabler. This happens when loading progressivly.
// Init from a disassembler. This happens when loading progressively.
convenience init(disassembler: Disassembler, scale: CGFloat, meta: APNGMeta) {
self.init(scale: scale, meta: meta)
self.disassembler = disassembler
Expand Down
25 changes: 15 additions & 10 deletions APNGKit/APNGImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ open class APNGImageView: APNGView {
}

image.reset()
setCurrentFrame()

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

if animating {
startAnimating()
}
Expand Down Expand Up @@ -219,7 +216,11 @@ open class APNGImageView: APNGView {
if isAnimating {
return
}


// Reset display content. It is necessary when restart the image view from a
// previous stop. https://github.com/onevcat/APNGKit/issues/96
setCurrentFrame()

isAnimating = true
timer = GCDTimer(intervalInSecs: 0.016)
timer!.Event = { [weak self] in
Expand Down Expand Up @@ -330,12 +331,16 @@ open class APNGImageView: APNGView {
}

currentPassedDuration = currentPassedDuration - currentFrameDuration

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

setCurrentFrame()
}

}

private func setCurrentFrame() {
guard let image = image else { return }
let frame = image.next(currentIndex: currentFrameIndex)
currentFrameDuration = frame.duration
updateContents(frame.image)
}

func updateContents(_ image: CocoaImage?) {
Expand Down

0 comments on commit df003ea

Please sign in to comment.