Merge pull request #2888 from dreampiggy/bugfix_animated_player_when_invisible
Fix the case even when Animated Image View is not visible, user calll startAnimating can still do animation
This commit is contained in:
commit
92d173e221
|
@ -108,6 +108,7 @@
|
|||
if (!_displayLink) {
|
||||
_displayLink = [SDDisplayLink displayLinkWithTarget:self selector:@selector(displayDidRefresh:)];
|
||||
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.runLoopMode];
|
||||
[_displayLink stop];
|
||||
}
|
||||
return _displayLink;
|
||||
}
|
||||
|
@ -197,7 +198,7 @@
|
|||
}
|
||||
|
||||
- (BOOL)isPlaying {
|
||||
return self.displayLink.isRunning;
|
||||
return _displayLink.isRunning;
|
||||
}
|
||||
|
||||
- (void)seekToFrameAtIndex:(NSUInteger)index loopCount:(NSUInteger)loopCount {
|
||||
|
|
|
@ -178,11 +178,8 @@
|
|||
// Ensure disabled highlighting; it's not supported (see `-setHighlighted:`).
|
||||
super.highlighted = NO;
|
||||
|
||||
// Update should animate
|
||||
[self updateShouldAnimate];
|
||||
if (self.shouldAnimate) {
|
||||
[self startAnimating];
|
||||
}
|
||||
// Start animating
|
||||
[self startAnimating];
|
||||
|
||||
[self.imageViewLayer setNeedsDisplay];
|
||||
}
|
||||
|
@ -312,7 +309,10 @@
|
|||
- (void)startAnimating
|
||||
{
|
||||
if (self.player) {
|
||||
[self.player startPlaying];
|
||||
[self updateShouldAnimate];
|
||||
if (self.shouldAnimate) {
|
||||
[self.player startPlaying];
|
||||
}
|
||||
} else {
|
||||
#if SD_UIKIT
|
||||
[super startAnimating];
|
||||
|
|
|
@ -108,12 +108,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testGIFData]];
|
||||
imageView.image = image;
|
||||
expect(imageView.image).notTo.beNil();
|
||||
#if SD_MAC
|
||||
imageView.animates = YES;
|
||||
#else
|
||||
[imageView startAnimating];
|
||||
#endif
|
||||
expect(imageView.currentFrame).notTo.beNil(); // current frame
|
||||
expect(imageView.player).notTo.beNil();
|
||||
}
|
||||
|
||||
- (void)test09AnimatedImageViewSetAnimatedImageAPNG {
|
||||
|
@ -121,12 +116,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
|
||||
imageView.image = image;
|
||||
expect(imageView.image).notTo.beNil();
|
||||
#if SD_MAC
|
||||
imageView.animates = YES;
|
||||
#else
|
||||
[imageView startAnimating];
|
||||
#endif
|
||||
expect(imageView.currentFrame).notTo.beNil(); // current frame
|
||||
expect(imageView.player).notTo.beNil();
|
||||
}
|
||||
|
||||
- (void)test10AnimatedImageInitWithCoder {
|
||||
|
@ -187,6 +177,27 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
expect(imageView.image).equal(image);
|
||||
}
|
||||
|
||||
- (void)test14AnimatedImageViewStopPlayingWhenHidden {
|
||||
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
|
||||
#if SD_UIKIT
|
||||
[self.window addSubview:imageView];
|
||||
#else
|
||||
[self.window.contentView addSubview:imageView];
|
||||
#endif
|
||||
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testGIFData]];
|
||||
imageView.image = image;
|
||||
#if SD_UIKIT
|
||||
[imageView startAnimating];
|
||||
#else
|
||||
imageView.animates = YES;
|
||||
#endif
|
||||
SDAnimatedImagePlayer *player = imageView.player;
|
||||
expect(player).notTo.beNil();
|
||||
expect(player.isPlaying).beTruthy();
|
||||
imageView.hidden = YES;
|
||||
expect(player.isPlaying).beFalsy();
|
||||
}
|
||||
|
||||
- (void)test20AnimatedImageViewRendering {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView rendering"];
|
||||
SDAnimatedImageView *imageView = [[SDAnimatedImageView alloc] init];
|
||||
|
@ -348,7 +359,7 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
|
|||
[self waitForExpectationsWithCommonTimeout];
|
||||
}
|
||||
|
||||
- (void)test25AnimatedImageStopAnimatingClearBuffer {
|
||||
- (void)test26AnimatedImageStopAnimatingClearBuffer {
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView stopAnimating clear buffer when stopped"];
|
||||
|
||||
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
|
||||
|
|
Loading…
Reference in New Issue