feat: Correct clear drawLayer.

This commit is contained in:
errnull
2019-10-17 16:05:35 +08:00
parent e6a0293950
commit 34ef59f599
4 changed files with 40 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 63712E6721787A45001AE014 /* SVGAAudioEntity.m */; };
63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E817002178809D001D2D62 /* SVGAAudioLayer.m */; };
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C92225E6F710029C69E /* mutiMatte.svga */; };
718A146D235718E000FED5D3 /* Rocket.svga in Resources */ = {isa = PBXBuildFile; fileRef = 718A146C235718E000FED5D3 /* Rocket.svga */; };
71A8679122B7785100176CD6 /* matteRect.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71A8679022B7785100176CD6 /* matteRect.svga */; };
71A8679322B7853600176CD6 /* matteBitmap.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71A8679222B7853600176CD6 /* matteBitmap.svga */; };
71DAA8A52355B3ED006608A1 /* Goddess.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71DAA8A42355B3ED006608A1 /* Goddess.svga */; };
@@ -68,6 +69,7 @@
63E816FF2178809D001D2D62 /* SVGAAudioLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAAudioLayer.h; sourceTree = "<group>"; };
63E817002178809D001D2D62 /* SVGAAudioLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioLayer.m; sourceTree = "<group>"; };
71418C92225E6F710029C69E /* mutiMatte.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMatte.svga; sourceTree = "<group>"; };
718A146C235718E000FED5D3 /* Rocket.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = Rocket.svga; sourceTree = "<group>"; };
71A8679022B7785100176CD6 /* matteRect.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = matteRect.svga; sourceTree = "<group>"; };
71A8679222B7853600176CD6 /* matteBitmap.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = matteBitmap.svga; sourceTree = "<group>"; };
71DAA8A42355B3ED006608A1 /* Goddess.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = Goddess.svga; sourceTree = "<group>"; };
@@ -247,6 +249,7 @@
90D7C9FA1F7E2AA3006E74F0 /* Samples */ = {
isa = PBXGroup;
children = (
718A146C235718E000FED5D3 /* Rocket.svga */,
71DAA8A42355B3ED006608A1 /* Goddess.svga */,
71A8679022B7785100176CD6 /* matteRect.svga */,
71A8679222B7853600176CD6 /* matteBitmap.svga */,
@@ -361,6 +364,7 @@
files = (
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */,
90A676F01D13A6DF008A69F3 /* LaunchScreen.storyboard in Resources */,
718A146D235718E000FED5D3 /* Rocket.svga in Resources */,
90A676ED1D13A6DF008A69F3 /* Assets.xcassets in Resources */,
63712E6521787950001AE014 /* heartbeat.svga in Resources */,
90A676EB1D13A6DF008A69F3 /* Main.storyboard in Resources */,

Binary file not shown.

View File

@@ -24,7 +24,7 @@ static SVGAParser *parser;
- (void)viewDidLoad {
[super viewDidLoad];
self.aPlayer.delegate = self;
self.aPlayer.loops = 0;
self.aPlayer.loops = 1;
self.aPlayer.clearsAfterStop = YES;
parser = [[SVGAParser alloc] init];
[self onChange:nil];
@@ -32,7 +32,6 @@ static SVGAParser *parser;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self onBeginButton:self.onBeginButton];
}
@@ -59,16 +58,16 @@ static SVGAParser *parser;
[self.aPlayer startAnimation];
}
} failureBlock:nil];
// [parser parseWithURL:[NSURL URLWithString:@"https://github.com/svga/SVGA-Samples/raw/master_aep/BitmapColorArea1.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
// if (videoItem != nil) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer setImageWithURL:[NSURL URLWithString: @"https://i.imgur.com/vd4GuUh.png"] forKey:@"matte_EEKdlEml.matte"];
// [self.aPlayer startAnimation];
// }
// } failureBlock:nil];
// [parser parseWithURL:[NSURL URLWithString:@"https://github.com/svga/SVGA-Samples/raw/master_aep/BitmapColorArea1.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
// if (videoItem != nil) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer setImageWithURL:[NSURL URLWithString: @"https://i.imgur.com/vd4GuUh.png"] forKey:@"matte_EEKdlEml.matte"];
// [self.aPlayer startAnimation];
// }
// } failureBlock:nil];
// [parser parseWithNamed:@"heartbeat" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// [parser parseWithNamed:@"Rocket" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer startAnimation];
// } failureBlock:nil];
@@ -91,7 +90,7 @@ static SVGAParser *parser;
if (sender.selected) {
[self.aPlayer pauseAnimation];
} else {
[self.aPlayer stepToPercentage:self.aSlider.value andPlay:YES];
[self.aPlayer stepToPercentage:(self.aSlider.value == 1 ? 0 : self.aSlider.value) andPlay:YES];
}
}
@@ -108,4 +107,8 @@ static SVGAParser *parser;
- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage {
self.aSlider.value = percentage;
}
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
self.onBeginButton.selected = YES;
}
@end

View File

@@ -74,6 +74,8 @@
if (self.videoItem == nil) {
NSLog(@"videoItem could not be nil");
return;
} else if (self.drawLayer == nil) {
self.videoItem = _videoItem;
}
[self stopAnimation:NO];
self.loopCount = 0;
@@ -117,8 +119,9 @@
}
- (void)clear {
_contentLayers = nil;
self.contentLayers = nil;
[self.drawLayer removeFromSuperlayer];
self.drawLayer = nil;
}
- (void)clearAudios {
@@ -132,6 +135,12 @@
}
- (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay {
if (self.videoItem == nil) {
NSLog(@"videoItem could not be nil");
return;
} else if (self.drawLayer == nil) {
self.videoItem = _videoItem;
}
if (frame >= self.videoItem.frames || frame < 0) {
return;
}
@@ -210,7 +219,7 @@
}
}
}];
_contentLayers = tempContentLayers;
self.contentLayers = tempContentLayers;
[self.layer addSublayer:self.drawLayer];
NSMutableArray *audioLayers = [NSMutableArray array];
@@ -303,7 +312,7 @@
- (void)update {
[CATransaction setDisableActions:YES];
for (SVGAContentLayer *layer in _contentLayers) {
for (SVGAContentLayer *layer in self.contentLayers) {
if ([layer isKindOfClass:[SVGAContentLayer class]]) {
[layer stepToFrame:self.currentFrame];
}
@@ -369,6 +378,7 @@
_currentRange = NSMakeRange(0, videoItem.frames);
_reversing = NO;
_currentFrame = 0;
_loopCount = 0;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self clear];
[self draw];
@@ -384,8 +394,8 @@
NSMutableDictionary *mutableDynamicObjects = [self.dynamicObjects mutableCopy];
[mutableDynamicObjects setObject:image forKey:aKey];
self.dynamicObjects = mutableDynamicObjects;
if (_contentLayers.count > 0) {
for (SVGAContentLayer *layer in _contentLayers) {
if (self.contentLayers.count > 0) {
for (SVGAContentLayer *layer in self.contentLayers) {
if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) {
layer.bitmapLayer.contents = (__bridge id _Nullable)([image CGImage]);
}
@@ -417,10 +427,10 @@
NSMutableDictionary *mutableDynamicTexts = [self.dynamicTexts mutableCopy];
[mutableDynamicTexts setObject:attributedText forKey:aKey];
self.dynamicTexts = mutableDynamicTexts;
if (_contentLayers.count > 0) {
if (self.contentLayers.count > 0) {
CGSize size = [attributedText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:NULL].size;
CATextLayer *textLayer;
for (SVGAContentLayer *layer in _contentLayers) {
for (SVGAContentLayer *layer in self.contentLayers) {
if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) {
textLayer = layer.textLayer;
if (textLayer == nil) {
@@ -442,8 +452,8 @@
NSMutableDictionary *mutableDynamicDrawings = [self.dynamicDrawings mutableCopy];
[mutableDynamicDrawings setObject:drawingBlock forKey:aKey];
self.dynamicDrawings = mutableDynamicDrawings;
if (_contentLayers.count > 0) {
for (SVGAContentLayer *layer in _contentLayers) {
if (self.contentLayers.count > 0) {
for (SVGAContentLayer *layer in self.contentLayers) {
if ([layer isKindOfClass:[SVGAContentLayer class]] &&
[layer.imageKey isEqualToString:aKey]) {
layer.dynamicDrawingBlock = drawingBlock;
@@ -456,8 +466,8 @@
NSMutableDictionary *mutableDynamicHiddens = [self.dynamicHiddens mutableCopy];
[mutableDynamicHiddens setObject:@(hidden) forKey:aKey];
self.dynamicHiddens = mutableDynamicHiddens;
if (_contentLayers.count > 0) {
for (SVGAContentLayer *layer in _contentLayers) {
if (self.contentLayers.count > 0) {
for (SVGAContentLayer *layer in self.contentLayers) {
if ([layer isKindOfClass:[SVGAContentLayer class]] &&
[layer.imageKey isEqualToString:aKey]) {
layer.dynamicHidden = hidden;