Optimize auto playback control

This commit is contained in:
liulichao 2020-05-07 21:23:52 +08:00
parent 03aaaac928
commit 26a765a71d
1 changed files with 19 additions and 38 deletions

View File

@ -184,12 +184,8 @@
// Ensure disabled highlighting; it's not supported (see `-setHighlighted:`). // Ensure disabled highlighting; it's not supported (see `-setHighlighted:`).
super.highlighted = NO; super.highlighted = NO;
if (self.autoPlayAnimatedImage) { [self stopAnimating];
// Start animating [self checkPlay];
[self startAnimating];
} else {
[self stopAnimating];
}
[self.imageViewLayer setNeedsDisplay]; [self.imageViewLayer setNeedsDisplay];
} }
@ -263,14 +259,7 @@
[super didMoveToSuperview]; [super didMoveToSuperview];
#endif #endif
if (self.autoPlayAnimatedImage) { [self checkPlay];
[self updateShouldAnimate];
if (self.shouldAnimate) {
[self startAnimating];
} else {
[self stopAnimating];
}
}
} }
#if SD_MAC #if SD_MAC
@ -285,14 +274,7 @@
[super didMoveToWindow]; [super didMoveToWindow];
#endif #endif
if (self.autoPlayAnimatedImage) { [self checkPlay];
[self updateShouldAnimate];
if (self.shouldAnimate) {
[self startAnimating];
} else {
[self stopAnimating];
}
}
} }
#if SD_MAC #if SD_MAC
@ -307,28 +289,14 @@
[super setAlpha:alpha]; [super setAlpha:alpha];
#endif #endif
if (self.autoPlayAnimatedImage) { [self checkPlay];
[self updateShouldAnimate];
if (self.shouldAnimate) {
[self startAnimating];
} else {
[self stopAnimating];
}
}
} }
- (void)setHidden:(BOOL)hidden - (void)setHidden:(BOOL)hidden
{ {
[super setHidden:hidden]; [super setHidden:hidden];
if (self.autoPlayAnimatedImage) { [self checkPlay];
[self updateShouldAnimate];
if (self.shouldAnimate) {
[self startAnimating];
} else {
[self stopAnimating];
}
}
} }
#pragma mark - UIImageView Method Overrides #pragma mark - UIImageView Method Overrides
@ -416,6 +384,19 @@
#pragma mark - Private Methods #pragma mark - Private Methods
#pragma mark Animation #pragma mark Animation
/// Check if it should be played
- (void)checkPlay
{
if (self.autoPlayAnimatedImage) {
[self updateShouldAnimate];
if (self.shouldAnimate) {
[self startAnimating];
} else {
[self stopAnimating];
}
}
}
// Don't repeatedly check our window & superview in `-displayDidRefresh:` for performance reasons. // Don't repeatedly check our window & superview in `-displayDidRefresh:` for performance reasons.
// Just update our cached value whenever the animated image or visibility (window, superview, hidden, alpha) is changed. // Just update our cached value whenever the animated image or visibility (window, superview, hidden, alpha) is changed.
- (void)updateShouldAnimate - (void)updateShouldAnimate