【OC-动画】SVGA 动画
程序员文章站
2022-03-02 19:45:19
...
声明:
此处仅仅只是作为记录开发中使用 SVGA 动画的笔记,所以没有进行相关动画知识的扩展。
#pragma mark --------------------
#pragma mark -------------------- SVGAPlayer --------------------
- (NSMutableArray *)svgaGiftArrayM {
if (!_svgaGiftArrayM) {
_svgaGiftArrayM = [NSMutableArray array];
}
return _svgaGiftArrayM;
}
/** 添加 SVGA 动画 **/
- (void)addSVGAAnimationWithGifId:(NSString *)gifId {
[self.svgaGiftArrayM addObject:gifId];
[self addSvgaPlayerAnimationWithGifId:gifId];
}
- (void)addSvgaPlayerAnimationWithGifId:(NSString *)gifId {
NSString *nameString;
if ([gifId isEqualToString:@"127"]) {
// nameString = @"posche-2_0";
nameString = @"127布加迪";
} else if ([gifId isEqualToString:@"128"]) {
nameString = @"rose_2.0.0";
} else if ([gifId isEqualToString:@"129"]) {
nameString = @"angel";
} else if ([gifId isEqualToString:@"130"]) {
nameString = @"change";
} else if ([gifId isEqualToString:@"132"]) {
nameString = @"132飞机";
} else if ([gifId isEqualToString:@"133"]) {
nameString = @"133火箭";
} else if ([gifId isEqualToString:@"134"]) {
nameString = @"134海岛";
} else if ([gifId isEqualToString:@"135"]) {
nameString = @"135樱花雨";
} else if ([gifId isEqualToString:@"136"]) {
nameString = @"136游轮";
}
if (!self.svgaPlayer && !self.svgaParser && self.svgaPlayNum == 0) {
self.svgaParser = [[SVGAParser alloc] init];
self.svgaPlayer = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, K_Screen_H-K_Screen_W*16/9, K_Screen_W, K_Screen_W*16/9)];
@K_Weakify(self)
[self.svgaPlayer jjc_view_addTapGestureWithBlock:^{
@K_Strongify(self)
[self zhezhaoBTNdelegate];
}];
[self.view insertSubview:self.svgaPlayer belowSubview:toolBar];
[self.svgaParser parseWithNamed:nameString inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
if (videoItem != nil) {
self.svgaPlayer.videoItem = videoItem;
self.svgaPlayer.delegate = self;
[self.svgaPlayer startAnimation];
}
} failureBlock:^(NSError * _Nonnull error) {
}];
}
}
- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage {
NSLog(@"--------------- percentage == %f ----------- ", percentage);
}
- (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame {
NSLog(@"--------------- frame == %ld ----------- ", frame);
if (frame == 59) {
self.svgaPlayNum++;
if (self.svgaPlayNum % 2 == 0) {
[self.svgaGiftArrayM removeObjectAtIndex:0];
[self.svgaPlayer stopAnimation];
[self.svgaPlayer clear];
self.svgaPlayNum = 0;
self.svgaParser = nil;
[self.svgaPlayer removeFromSuperview];
self.svgaPlayer = nil;
[self checkIsGoSvgaPlayAnimation];
}
}
}
- (void)checkIsGoSvgaPlayAnimation {
if (self.svgaGiftArrayM.count > 0) {
NSString *gifId = self.svgaGiftArrayM[0];
[self addSvgaPlayerAnimationWithGifId:gifId];
}
}
上一篇: CSS动画
下一篇: 在react项目中播放svga动画