lazy load maskPath.

This commit is contained in:
PonyCui
2017-09-30 19:52:48 +08:00
parent 1930e66d20
commit 28bf90f1e8
2 changed files with 15 additions and 8 deletions

View File

@@ -38,13 +38,14 @@ static SVGAParser *parser;
}
- (IBAction)onChange:(id)sender {
NSString *named = @"rose_2.0.0";
NSString *named = @"rose_1.5.0";
NSLog(@"start");
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:named ofType:@"svga"]
options:kNilOptions
error:NULL];
[parser parseWithData:data
cacheKey:named completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
NSLog(@"end");
if (videoItem != nil) {
self.aPlayer.videoItem = videoItem;
[self.aPlayer startAnimation];

View File

@@ -19,6 +19,7 @@
@property (nonatomic, assign) CGRect layout;
@property (nonatomic, assign) CGFloat nx;
@property (nonatomic, assign) CGFloat ny;
@property (nonatomic, strong) NSString *clipPath;
@property (nonatomic, strong) CALayer *maskLayer;
@property (nonatomic, strong) NSArray *shapes;
@@ -61,9 +62,7 @@
}
NSString *clipPath = JSONObject[@"clipPath"];
if ([clipPath isKindOfClass:[NSString class]]) {
SVGABezierPath *bezierPath = [[SVGABezierPath alloc] init];
[bezierPath setValues:clipPath];
self.maskLayer = [bezierPath createLayer];
self.clipPath = clipPath;
}
NSArray *shapes = JSONObject[@"shapes"];
if ([shapes isKindOfClass:[NSArray class]]) {
@@ -107,9 +106,7 @@
(CGFloat)protoObject.transform.ty);
}
if ([protoObject.clipPath isKindOfClass:[NSString class]] && protoObject.clipPath.length > 0) {
SVGABezierPath *bezierPath = [[SVGABezierPath alloc] init];
[bezierPath setValues:protoObject.clipPath];
self.maskLayer = [bezierPath createLayer];
self.clipPath = protoObject.clipPath;
}
if ([protoObject.shapesArray isKindOfClass:[NSArray class]]) {
_shapes = [protoObject.shapesArray copy];
@@ -129,4 +126,13 @@
return self;
}
- (CALayer *)maskLayer {
if (_maskLayer == nil && self.clipPath != nil) {
SVGABezierPath *bezierPath = [[SVGABezierPath alloc] init];
[bezierPath setValues:self.clipPath];
_maskLayer = [bezierPath createLayer];
}
return _maskLayer;
}
@end