diff --git a/SDWebImage/Core/SDAnimatedImageView.h b/SDWebImage/Core/SDAnimatedImageView.h index 3a809edd..1fca1f93 100644 --- a/SDWebImage/Core/SDAnimatedImageView.h +++ b/SDWebImage/Core/SDAnimatedImageView.h @@ -20,13 +20,6 @@ */ @interface SDAnimatedImageView : UIImageView -/** - If the image has more than one frame, set this value to `YES` will automatically - play/stop the animation when the view become visible/invisible. - - The default value is `YES`. - */ -@property (nonatomic) BOOL autoPlayAnimatedImage; /** Current display frame image. This value is KVO Compliance. */ @@ -88,6 +81,14 @@ */ @property (nonatomic, assign) BOOL resetFrameIndexWhenStopped; +/** + If the image has more than one frame, set this value to `YES` will automatically + play/stop the animation when the view become visible/invisible. + + The default value is `YES`. + */ +@property (nonatomic) BOOL autoPlayAnimatedImage; + /** You can specify a runloop mode to let it rendering. Default is NSRunLoopCommonModes on multi-core device, NSDefaultRunLoopMode on single-core device diff --git a/Tests/Tests/SDAnimatedImageTest.m b/Tests/Tests/SDAnimatedImageTest.m index 0640e3dc..9bf26411 100644 --- a/Tests/Tests/SDAnimatedImageTest.m +++ b/Tests/Tests/SDAnimatedImageTest.m @@ -468,6 +468,50 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun [self waitForExpectationsWithCommonTimeout]; } +- (void)test28AnimatedImageAutoPlayAnimatedImage { + XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView AutoPlayAnimatedImage behavior"]; + + SDAnimatedImageView *imageView = [SDAnimatedImageView new]; + imageView.autoPlayAnimatedImage = NO; + +#if SD_UIKIT + [self.window addSubview:imageView]; +#else + [self.window.contentView addSubview:imageView]; +#endif + // This APNG duration is 2s + SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]]; + imageView.image = image; + + expect(imageView.animating).equal(0); + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + expect(imageView.animating).equal(0); + + #if SD_UIKIT + [imageView startAnimating]; + #else + imageView.animates = YES; + #endif + + expect(imageView.animating).equal(1); + }); + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + expect(imageView.animating).equal(1); + + #if SD_UIKIT + [imageView stopAnimating]; + #else + imageView.animates = NO; + #endif + [imageView removeFromSuperview]; + [expectation fulfill]; + }); + + [self waitForExpectationsWithCommonTimeout]; +} + #pragma mark - Helper - (UIWindow *)window { if (!_window) {