mirror of
https://github.com/svga/SVGAPlayer-iOS.git
synced 2025-10-21 07:29:14 +08:00
improve: now setText can set at anytime.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
@property (nonatomic, strong) NSString *imageKey;
|
||||
@property (nonatomic, strong) SVGABitmapLayer *bitmapLayer;
|
||||
@property (nonatomic, strong) SVGAVectorLayer *vectorLayer;
|
||||
@property (nonatomic, strong) CATextLayer *textLayer;
|
||||
|
||||
- (instancetype)initWithFrames:(NSArray<SVGAVideoSpriteFrameEntity *> *)frames;
|
||||
|
||||
|
@@ -123,6 +123,7 @@
|
||||
[textLayer setString:self.dynamicTexts[sprite.imageKey]];
|
||||
textLayer.frame = CGRectMake(0, 0, size.width, size.height);
|
||||
[contentLayer addSublayer:textLayer];
|
||||
contentLayer.textLayer = textLayer;
|
||||
}
|
||||
}
|
||||
}];
|
||||
@@ -297,6 +298,24 @@
|
||||
NSMutableDictionary *mutableDynamicTexts = [self.dynamicTexts mutableCopy];
|
||||
[mutableDynamicTexts setObject:attributedText forKey:aKey];
|
||||
self.dynamicTexts = mutableDynamicTexts;
|
||||
if (self.drawLayer.sublayers.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) {
|
||||
if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) {
|
||||
textLayer = layer.textLayer;
|
||||
if (textLayer == nil) {
|
||||
textLayer = [CATextLayer layer];
|
||||
[layer addSublayer:textLayer];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (textLayer != nil) {
|
||||
textLayer.contentsScale = [[UIScreen mainScreen] scale];
|
||||
[textLayer setString:attributedText];
|
||||
textLayer.frame = CGRectMake(0, 0, size.width, size.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)clearDynamicObjects {
|
||||
|
Reference in New Issue
Block a user