로컬 gif 이미지가 한 번만 재생되는 경우도 있습니다. 여기서는 FLAnimationImageView를 사용하여
FLAnimationImageView 수정
forcePause 속성 추가
@interface FLAnimatedImageView : UIImageView
@property (nonatomic, assign) BOOL forcePaused;
@end
타이머 방식
self.displayLink = [CADisplayLink displayLinkWithTarget:weakProxy selector:@selector(displayDidRefresh:)];
타이머 메소드를 수정
하고 다음 문장을 추가하세요.
if (self.forcePaused) {
self.image = self.currentFrame;
return;
}
종료 콜백 설정
- (FLAnimatedImageView *)imgView
{
if (!_imgView) {
_imgView = [[FLAnimatedImageView alloc] init];
__weak FLAnimatedImageView *weakImgView = _imgView;
_imgView.loopCompletionBlock = ^(NSUInteger loopCountRemaining) {
weakImgView.forcePaused = YES;
[weakImgView stopAnimating];
};
}
return _imgView;
}
- (void)displayDidRefresh:(CADisplayLink *)displayLink
{
// If for some reason a wild call makes it through when we shouldn't be animating, bail.
// Early return!
if (!self.shouldAnimate) {
FLLog(FLLogLevelWarn, @"Trying to animate image when we shouldn't: %@", self);
return;
}
if (self.forcePaused) {
self.image = self.currentFrame;
return;
}
。。。。
GIF 리소스 표시
NSString *path = [[NSBundle mainBundle] pathForResource:@"animation_24hlive" ofType:@"gif"];
NSData *gifData = [NSData dataWithContentsOfFile:path];
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:gifData];
_animationView.animatedImage = image;