From 28bf90f1e891a4e76f9c5d244ecb5317ba89f947 Mon Sep 17 00:00:00 2001 From: PonyCui Date: Sat, 30 Sep 2017 19:52:48 +0800 Subject: [PATCH] lazy load maskPath. --- SVGAPlayer/ViewController.m | 5 +++-- Source/SVGAVideoSpriteFrameEntity.m | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/SVGAPlayer/ViewController.m b/SVGAPlayer/ViewController.m index d8f9254..11b61e4 100644 --- a/SVGAPlayer/ViewController.m +++ b/SVGAPlayer/ViewController.m @@ -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]; diff --git a/Source/SVGAVideoSpriteFrameEntity.m b/Source/SVGAVideoSpriteFrameEntity.m index 5b6dc37..74f2dc0 100644 --- a/Source/SVGAVideoSpriteFrameEntity.m +++ b/Source/SVGAVideoSpriteFrameEntity.m @@ -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