forked from svga/SVGAPlayer-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVGAVideoSpriteEntity.m
More file actions
74 lines (68 loc) · 2.91 KB
/
SVGAVideoSpriteEntity.m
File metadata and controls
74 lines (68 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// SVGAVideoSpriteEntity.m
// SVGAPlayer
//
// Created by 崔明辉 on 2017/2/20.
// Copyright © 2017年 UED Center. All rights reserved.
//
#import "SVGAVideoSpriteEntity.h"
#import "SVGAVideoSpriteFrameEntity.h"
#import "SVGABitmapLayer.h"
#import "SVGAContentLayer.h"
#import "SVGAVectorLayer.h"
#import "Svga.pbobjc.h"
@implementation SVGAVideoSpriteEntity
- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
self = [super init];
if (self) {
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
NSString *imageKey = JSONObject[@"imageKey"];
NSString *matteKey = JSONObject[@"matteKey"];
NSArray<NSDictionary *> *JSONFrames = JSONObject[@"frames"];
if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) {
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
[JSONFrames enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[NSDictionary class]]) {
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithJSONObject:obj]];
}
}];
_imageKey = imageKey;
_frames = frames;
_matteKey = matteKey;
}
}
}
return self;
}
- (instancetype)initWithProtoObject:(SVGAProtoSpriteEntity *)protoObject {
self = [super init];
if (self) {
if ([protoObject isKindOfClass:[SVGAProtoSpriteEntity class]]) {
NSString *imageKey = protoObject.imageKey;
NSString *matteKey = protoObject.matteKey;
NSArray<NSDictionary *> *protoFrames = [protoObject.framesArray copy];
if ([imageKey isKindOfClass:[NSString class]] && [protoFrames isKindOfClass:[NSArray class]]) {
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
[protoFrames enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[SVGAProtoFrameEntity class]]) {
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithProtoObject:obj]];
}
}];
_imageKey = imageKey;
_frames = frames;
_matteKey = matteKey;
}
}
}
return self;
}
- (SVGAContentLayer *)requestLayerWithBitmap:(UIImage *)bitmap {
SVGAContentLayer *layer = [[SVGAContentLayer alloc] initWithFrames:self.frames];
if (bitmap != nil) {
layer.bitmapLayer = [[SVGABitmapLayer alloc] initWithFrames:self.frames];
layer.bitmapLayer.contents = (__bridge id _Nullable)([bitmap CGImage]);
}
layer.vectorLayer = [[SVGAVectorLayer alloc] initWithFrames:self.frames];
return layer;
}
@end