Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Source/Classes/AnimatedImages/PINAnimatedImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ @interface PINAnimatedImageView ()

@end


@implementation PINAnimatedImageView

@synthesize animatedImage = _animatedImage;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions Source/Classes/include/PINAnimatedImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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