improve: now setText can set at anytime.

This commit is contained in:
PonyCui
2017-11-08 16:57:50 +08:00
parent afd206bb1e
commit 45274cb0a4
2 changed files with 20 additions and 0 deletions

View File

@@ -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;

View File

@@ -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 {