Merge pull request #3113 from MoZhouqi/master

Add animationImages support when using SDAnimatedImageView
This commit is contained in:
DreamPiggy 2020-11-03 10:26:39 +08:00 committed by GitHub
commit 264d7a490c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -14,7 +14,7 @@
/** /**
A drop-in replacement for UIImageView/NSImageView, you can use this for animated image rendering. A drop-in replacement for UIImageView/NSImageView, you can use this for animated image rendering.
Call `setImage:` with `UIImage(NSImage)` which conform to `SDAnimatedImage` protocol will start animated image rendering. Call with normal UIImage(NSImage) will back to normal UIImageView(NSImageView) rendering Call `setImage:` with `UIImage(NSImage)` which conforms to `SDAnimatedImage` protocol will start animated image rendering. Call with normal UIImage(NSImage) will back to normal UIImageView(NSImageView) rendering
For UIKit: use `-startAnimating`, `-stopAnimating` to control animating. `isAnimating` to check animation state. For UIKit: use `-startAnimating`, `-stopAnimating` to control animating. `isAnimating` to check animation state.
For AppKit: use `-setAnimates:` to control animating, `animates` to check animation state. This view is layer-backed. For AppKit: use `-setAnimates:` to control animating, `animates` to check animation state. This view is layer-backed.
*/ */
@ -82,7 +82,7 @@
@property (nonatomic, assign) BOOL resetFrameIndexWhenStopped; @property (nonatomic, assign) BOOL resetFrameIndexWhenStopped;
/** /**
If the image has more than one frame, set this value to `YES` will automatically If the image which conforms to `SDAnimatedImage` protocol has more than one frame, set this value to `YES` will automatically
play/stop the animation when the view become visible/invisible. play/stop the animation when the view become visible/invisible.
Default is YES. Default is YES.
*/ */

View File

@ -402,7 +402,8 @@
/// Check if it should be played /// Check if it should be played
- (void)checkPlay - (void)checkPlay
{ {
if (self.autoPlayAnimatedImage) { // Only handle for SDAnimatedImage, leave UIAnimatedImage or animationImages for super implementation control
if (self.player && self.autoPlayAnimatedImage) {
[self updateShouldAnimate]; [self updateShouldAnimate];
if (self.shouldAnimate) { if (self.shouldAnimate) {
[self startAnimating]; [self startAnimating];

View File

@ -602,6 +602,26 @@ static BOOL _isCalled;
expect(SDImageAPNGTestCoder.isCalled).equal(YES); expect(SDImageAPNGTestCoder.isCalled).equal(YES);
} }
#if SD_UIKIT
- (void)test31AnimatedImageViewSetAnimationImages {
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
UIImage *image = [[UIImage alloc] initWithData:[self testJPEGData]];
imageView.animationImages = @[image];
expect(imageView.animationImages).notTo.beNil();
}
- (void)test32AnimatedImageViewNotStopPlayingAnimationImagesWhenHidden {
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
[self.window addSubview:imageView];
UIImage *image = [[UIImage alloc] initWithData:[self testJPEGData]];
imageView.animationImages = @[image];
[imageView startAnimating];
expect(imageView.animating).beTruthy();
imageView.hidden = YES;
expect(imageView.animating).beTruthy();
}
#endif
#pragma mark - Helper #pragma mark - Helper
- (UIWindow *)window { - (UIWindow *)window {
if (!_window) { if (!_window) {