diff --git a/Source/Classes/AnimatedImages/PINAnimatedImageView.m b/Source/Classes/AnimatedImages/PINAnimatedImageView.m index 4adc36a3..fd640a18 100644 --- a/Source/Classes/AnimatedImages/PINAnimatedImageView.m +++ b/Source/Classes/AnimatedImages/PINAnimatedImageView.m @@ -27,6 +27,7 @@ @interface PINAnimatedImageView () @end + @implementation PINAnimatedImageView @synthesize animatedImage = _animatedImage; @@ -106,6 +107,13 @@ - (void)dealloc #pragma mark - Public +-(void)setAnimatedImage:(PINCachedAnimatedImage*)image atTimestamp:(CFTimeInterval)newTimestamp +{ + [self setAnimatedImage:image]; + + [self setCurrentTimestamp:newTimestamp]; +} + - (void)setAnimatedImage:(PINCachedAnimatedImage *)animatedImage { PINAssertMain(); @@ -190,12 +198,39 @@ - (void)setCoverImage:(PINImage *)coverImage _frameImage = CGImageRetain([coverImage CGImage]); } +-(CFTimeInterval)lastDisplayedTimestamp +{ + return _playHead; +} + +-(void)setCurrentTimestamp:(CFTimeInterval)newTimestamp +{ + if (_displayLink == nil) { + [self startAnimating]; + + _playHead = newTimestamp; + } + else { + // Reset + _displayLink.paused = YES; + _displayLink.paused = NO; + + _lastDisplayLinkFire = 0; + _playedLoops = 0; + + _playHead = newTimestamp; + + [self displayLinkFired:_displayLink]; + } +} + #pragma mark - Animating - (void)checkIfShouldAnimate { PINAssertMain(); BOOL shouldAnimate = _playbackPaused == NO && _animatedImage.playbackReady && [self canBeVisible]; + if (shouldAnimate) { [self startAnimating]; } else { diff --git a/Source/Classes/include/PINAnimatedImageView.h b/Source/Classes/include/PINAnimatedImageView.h index b224f025..9dfce310 100644 --- a/Source/Classes/include/PINAnimatedImageView.h +++ b/Source/Classes/include/PINAnimatedImageView.h @@ -25,4 +25,10 @@ @property (nullable, nonatomic, strong) NSString *animatedImageRunLoopMode; @property (nonatomic, assign, getter=isPlaybackPaused) BOOL playbackPaused; +@property (nonatomic, readonly) CFTimeInterval lastDisplayedTimestamp; + +-(void)setCurrentTimestamp:(CFTimeInterval)newTimestamp; + +-(void)setAnimatedImage:(nullable PINCachedAnimatedImage*)image atTimestamp:(CFTimeInterval)newTimestamp; + @end