Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Querying and Setting the Playback Timestamp in PINAnimatedImageView #623

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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