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
48 lines (43 loc) · 1.72 KB
/
SVGAVideoSpriteEntity.m
File metadata and controls
48 lines (43 loc) · 1.72 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
//
// 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"
@implementation SVGAVideoSpriteEntity
- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
self = [super init];
if (self) {
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
NSString *imageKey = JSONObject[@"imageKey"];
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;
}
}
}
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