mirror of
https://github.com/svga/SVGAPlayer-iOS.git
synced 2025-10-21 07:29:14 +08:00
Add dynamic Text.
This commit is contained in:
@@ -49,6 +49,18 @@
|
||||
iconLayer.borderColor = [UIColor colorWithRed:0xea/255.0 green:0xb3/255.0 blue:0x7d/255.0 alpha:1.0].CGColor;
|
||||
[self.aPlayer setImage:iconImage forKey:@"99" referenceLayer:iconLayer];
|
||||
}
|
||||
{
|
||||
NSShadow *shadow = [NSShadow new];
|
||||
shadow.shadowColor = [UIColor blackColor];
|
||||
shadow.shadowOffset = CGSizeMake(0, 1);
|
||||
NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"崔小姐不吃鱼 送了魔法奇缘"
|
||||
attributes:@{
|
||||
NSForegroundColorAttributeName: [UIColor colorWithRed:0xff/255.0 green:0xe0/255.0 blue:0xa4/255.0 alpha:1.0],
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:30.0],
|
||||
NSShadowAttributeName: shadow,
|
||||
}];
|
||||
[self.aPlayer setAttributedText:text forKey:@"banner"];
|
||||
}
|
||||
self.aPlayer.videoItem = videoItem;
|
||||
[self.aPlayer startAnimation];
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#pragma mark - Dynamic Object
|
||||
|
||||
- (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer;
|
||||
- (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey;
|
||||
- (void)clearDynamicObjects;
|
||||
|
||||
@end
|
||||
|
@@ -18,6 +18,7 @@
|
||||
@property (nonatomic, assign) int currentFrame;
|
||||
@property (nonatomic, copy) NSDictionary *dynamicObjects;
|
||||
@property (nonatomic, copy) NSDictionary *dynamicLayers;
|
||||
@property (nonatomic, copy) NSDictionary *dynamicTexts;
|
||||
|
||||
@end
|
||||
|
||||
@@ -75,6 +76,14 @@
|
||||
else {
|
||||
spriteLayer.contents = (__bridge id _Nullable)([self.videoItem.images[sprite.imageKey] CGImage]);
|
||||
}
|
||||
if (self.dynamicTexts[sprite.imageKey] != nil) {
|
||||
NSAttributedString *text = self.dynamicTexts[sprite.imageKey];
|
||||
CGSize size = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:NULL].size;
|
||||
CATextLayer *textLayer = [CATextLayer layer];
|
||||
[textLayer setString:self.dynamicTexts[sprite.imageKey]];
|
||||
textLayer.frame = CGRectMake(0, 0, size.width, size.height);
|
||||
[spriteLayer addSublayer:textLayer];
|
||||
}
|
||||
[self.drawLayer addSublayer:spriteLayer];
|
||||
}
|
||||
}];
|
||||
@@ -117,6 +126,14 @@
|
||||
CGFloat offsetY = layer.frame.origin.y - ny;
|
||||
layer.position = CGPointMake(layer.position.x - offsetX, layer.position.y - offsetY);
|
||||
layer.mask = frameItem.maskLayer;
|
||||
for (CALayer *sublayer in layer.sublayers) {
|
||||
if ([sublayer isKindOfClass:[CATextLayer class]]) {
|
||||
CGRect frame = sublayer.frame;
|
||||
frame.origin.x = (layer.frame.size.width - sublayer.frame.size.width) / 2.0;
|
||||
frame.origin.y = (layer.frame.size.height - sublayer.frame.size.height) / 2.0;
|
||||
sublayer.frame = frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
layer.hidden = YES;
|
||||
@@ -168,6 +185,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey {
|
||||
if (attributedText == nil) {
|
||||
return;
|
||||
}
|
||||
NSMutableDictionary *mutableDynamicTexts = [self.dynamicTexts mutableCopy];
|
||||
[mutableDynamicTexts setObject:attributedText forKey:aKey];
|
||||
self.dynamicTexts = mutableDynamicTexts;
|
||||
}
|
||||
|
||||
- (void)clearDynamicObjects {
|
||||
self.dynamicObjects = nil;
|
||||
self.dynamicLayers = nil;
|
||||
@@ -187,4 +213,11 @@
|
||||
return _dynamicLayers;
|
||||
}
|
||||
|
||||
- (NSDictionary *)dynamicTexts {
|
||||
if (_dynamicTexts == nil) {
|
||||
_dynamicTexts = @{};
|
||||
}
|
||||
return _dynamicTexts;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user