mirror of
https://github.com/svga/SVGAPlayer-iOS.git
synced 2025-10-21 07:29:14 +08:00
feat: support muti mask.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
63712E6521787950001AE014 /* heartbeat.svga in Resources */ = {isa = PBXBuildFile; fileRef = 63712E6421787950001AE014 /* heartbeat.svga */; };
|
||||
63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 63712E6721787A45001AE014 /* SVGAAudioEntity.m */; };
|
||||
63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E817002178809D001D2D62 /* SVGAAudioLayer.m */; };
|
||||
71418C712259FAA30029C69E /* mutiMask.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C702259FAA30029C69E /* mutiMask.svga */; };
|
||||
80D4C7254846B96B9C6EED83 /* libPods-SVGAPlayer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */; };
|
||||
904D41F81D223DD20085A21A /* SVGABezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 904D41F71D223DD20085A21A /* SVGABezierPath.m */; };
|
||||
9052FC631E6EB8D4007BC925 /* SVGAExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */; };
|
||||
@@ -63,6 +64,7 @@
|
||||
63712E6721787A45001AE014 /* SVGAAudioEntity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioEntity.m; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
71418C702259FAA30029C69E /* mutiMask.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMask.svga; sourceTree = "<group>"; };
|
||||
8AD65028FA2D122A34DC4A63 /* Pods-SVGAPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
904D41F61D223DD20085A21A /* SVGABezierPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGABezierPath.h; sourceTree = "<group>"; };
|
||||
904D41F71D223DD20085A21A /* SVGABezierPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGABezierPath.m; sourceTree = "<group>"; };
|
||||
@@ -239,6 +241,7 @@
|
||||
90D7C9FA1F7E2AA3006E74F0 /* Samples */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
71418C702259FAA30029C69E /* mutiMask.svga */,
|
||||
63712E6421787950001AE014 /* heartbeat.svga */,
|
||||
90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */,
|
||||
90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */,
|
||||
@@ -327,6 +330,7 @@
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
English,
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
@@ -350,6 +354,7 @@
|
||||
90A676ED1D13A6DF008A69F3 /* Assets.xcassets in Resources */,
|
||||
63712E6521787950001AE014 /* heartbeat.svga in Resources */,
|
||||
90A676EB1D13A6DF008A69F3 /* Main.storyboard in Resources */,
|
||||
71418C712259FAA30029C69E /* mutiMask.svga in Resources */,
|
||||
90CB64F91EF297E800DAA382 /* SVGAPlayer React-Info.plist in Resources */,
|
||||
90D7CA1C1F7FB114006E74F0 /* rose_1.5.0.svga in Resources */,
|
||||
90D7CA1B1F7FB114006E74F0 /* rose_2.0.0.svga in Resources */,
|
||||
|
BIN
SVGAPlayer/Samples/mutiMask.svga
Normal file
BIN
SVGAPlayer/Samples/mutiMask.svga
Normal file
Binary file not shown.
@@ -29,7 +29,14 @@ static SVGAParser *parser;
|
||||
self.aPlayer.loops = 0;
|
||||
self.aPlayer.clearsAfterStop = YES;
|
||||
parser = [[SVGAParser alloc] init];
|
||||
[self onChange:nil];
|
||||
[parser parseWithNamed:@"mutiMask"
|
||||
inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
||||
if (videoItem != nil) {
|
||||
self.aPlayer.videoItem = videoItem;
|
||||
[self.aPlayer startAnimation];
|
||||
}
|
||||
} failureBlock:^(NSError * _Nonnull error) {
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews {
|
||||
|
@@ -35,6 +35,8 @@
|
||||
|
||||
@implementation SVGAPlayer
|
||||
|
||||
static NSArray *_contentLayers;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
@@ -55,6 +57,7 @@
|
||||
[self stopAnimation:NO];
|
||||
self.loopCount = 0;
|
||||
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
|
||||
|
||||
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
|
||||
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
||||
self.forwardAnimating = !self.reversing;
|
||||
@@ -93,6 +96,7 @@
|
||||
}
|
||||
|
||||
- (void)clear {
|
||||
_contentLayers = nil;
|
||||
[self.drawLayer removeFromSuperlayer];
|
||||
}
|
||||
|
||||
@@ -128,7 +132,9 @@
|
||||
self.drawLayer = [[CALayer alloc] init];
|
||||
self.drawLayer.frame = CGRectMake(0, 0, self.videoItem.videoSize.width, self.videoItem.videoSize.height);
|
||||
self.drawLayer.masksToBounds = true;
|
||||
[self.videoItem.sprites enumerateObjectsUsingBlock:^(SVGAVideoSpriteEntity * _Nonnull sprite, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
NSMutableDictionary *tempHostLayers = [NSMutableDictionary dictionary];
|
||||
NSMutableDictionary *tempContentLayers = [NSMutableDictionary dictionary];
|
||||
for (SVGAVideoSpriteEntity * sprite in self.videoItem.sprites) {
|
||||
UIImage *bitmap;
|
||||
if (sprite.imageKey != nil) {
|
||||
if (self.dynamicObjects[sprite.imageKey] != nil) {
|
||||
@@ -140,7 +146,20 @@
|
||||
}
|
||||
SVGAContentLayer *contentLayer = [sprite requestLayerWithBitmap:bitmap];
|
||||
contentLayer.imageKey = sprite.imageKey;
|
||||
[self.drawLayer addSublayer:contentLayer];
|
||||
tempContentLayers[sprite.imageKey] = contentLayer;
|
||||
if ([sprite.imageKey containsString:@".mask"]) {
|
||||
CALayer *hostLayer = [[CALayer alloc] init];
|
||||
hostLayer.mask = contentLayer;
|
||||
[self.drawLayer addSublayer:hostLayer];
|
||||
tempHostLayers[sprite.imageKey] = hostLayer;
|
||||
} else {
|
||||
if (sprite.maskImageKey) {
|
||||
CALayer *hostLayer = tempHostLayers[sprite.maskImageKey];
|
||||
[hostLayer addSublayer:contentLayer];
|
||||
} else {
|
||||
[self.drawLayer addSublayer:contentLayer];
|
||||
}
|
||||
}
|
||||
if (sprite.imageKey != nil) {
|
||||
if (self.dynamicTexts[sprite.imageKey] != nil) {
|
||||
NSAttributedString *text = self.dynamicTexts[sprite.imageKey];
|
||||
@@ -160,7 +179,11 @@
|
||||
contentLayer.dynamicDrawingBlock = self.dynamicDrawings[sprite.imageKey];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
_contentLayers = tempContentLayers.allValues;
|
||||
// [self.videoItem.sprites enumerateObjectsUsingBlock:^(SVGAVideoSpriteEntity * _Nonnull sprite, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
|
||||
// }];
|
||||
[self.layer addSublayer:self.drawLayer];
|
||||
NSMutableArray *audioLayers = [NSMutableArray array];
|
||||
[self.videoItem.audios enumerateObjectsUsingBlock:^(SVGAAudioEntity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
@@ -252,7 +275,7 @@
|
||||
|
||||
- (void)update {
|
||||
[CATransaction setDisableActions:YES];
|
||||
for (SVGAContentLayer *layer in self.drawLayer.sublayers) {
|
||||
for (SVGAContentLayer *layer in _contentLayers) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]]) {
|
||||
[layer stepToFrame:self.currentFrame];
|
||||
}
|
||||
@@ -331,8 +354,8 @@
|
||||
NSMutableDictionary *mutableDynamicObjects = [self.dynamicObjects mutableCopy];
|
||||
[mutableDynamicObjects setObject:image forKey:aKey];
|
||||
self.dynamicObjects = mutableDynamicObjects;
|
||||
if (self.drawLayer.sublayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in self.drawLayer.sublayers) {
|
||||
if (_contentLayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in _contentLayers) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) {
|
||||
layer.bitmapLayer.contents = (__bridge id _Nullable)([image CGImage]);
|
||||
}
|
||||
@@ -364,10 +387,10 @@
|
||||
NSMutableDictionary *mutableDynamicTexts = [self.dynamicTexts mutableCopy];
|
||||
[mutableDynamicTexts setObject:attributedText forKey:aKey];
|
||||
self.dynamicTexts = mutableDynamicTexts;
|
||||
if (self.drawLayer.sublayers.count > 0) {
|
||||
if (_contentLayers.count > 0) {
|
||||
CGSize size = [attributedText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:NULL].size;
|
||||
CATextLayer *textLayer;
|
||||
for (SVGAContentLayer *layer in self.drawLayer.sublayers) {
|
||||
for (SVGAContentLayer *layer in _contentLayers) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) {
|
||||
textLayer = layer.textLayer;
|
||||
if (textLayer == nil) {
|
||||
@@ -389,8 +412,8 @@
|
||||
NSMutableDictionary *mutableDynamicDrawings = [self.dynamicDrawings mutableCopy];
|
||||
[mutableDynamicDrawings setObject:drawingBlock forKey:aKey];
|
||||
self.dynamicDrawings = mutableDynamicDrawings;
|
||||
if (self.drawLayer.sublayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in self.drawLayer.sublayers) {
|
||||
if (_contentLayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in _contentLayers) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]] &&
|
||||
[layer.imageKey isEqualToString:aKey]) {
|
||||
layer.dynamicDrawingBlock = drawingBlock;
|
||||
@@ -403,8 +426,8 @@
|
||||
NSMutableDictionary *mutableDynamicHiddens = [self.dynamicHiddens mutableCopy];
|
||||
[mutableDynamicHiddens setObject:@(hidden) forKey:aKey];
|
||||
self.dynamicHiddens = mutableDynamicHiddens;
|
||||
if (self.drawLayer.sublayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in self.drawLayer.sublayers) {
|
||||
if (_contentLayers.count > 0) {
|
||||
for (SVGAContentLayer *layer in _contentLayers) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]] &&
|
||||
[layer.imageKey isEqualToString:aKey]) {
|
||||
layer.dynamicHidden = hidden;
|
||||
|
@@ -15,6 +15,7 @@
|
||||
@interface SVGAVideoSpriteEntity : NSObject
|
||||
|
||||
@property (nonatomic, readonly) NSString *imageKey;
|
||||
@property (nonatomic, readonly) NSString *maskImageKey;
|
||||
@property (nonatomic, readonly) NSArray<SVGAVideoSpriteFrameEntity *> *frames;
|
||||
|
||||
- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject;
|
||||
|
@@ -20,6 +20,7 @@
|
||||
if (self) {
|
||||
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
|
||||
NSString *imageKey = JSONObject[@"imageKey"];
|
||||
NSString *maskImageKey = JSONObject[@"maskImageKey"];
|
||||
NSArray<NSDictionary *> *JSONFrames = JSONObject[@"frames"];
|
||||
if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) {
|
||||
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
|
||||
@@ -28,6 +29,7 @@
|
||||
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithJSONObject:obj]];
|
||||
}
|
||||
}];
|
||||
_maskImageKey = maskImageKey;
|
||||
_imageKey = imageKey;
|
||||
_frames = frames;
|
||||
}
|
||||
|
Reference in New Issue
Block a user