0
레이어가 있고 drawInContext:
에 drawInRect:
이라는 속성이있는 문자열을 그립니다. 다음은 레이어를 초기화하는 방법입니다.NSMutableAttributedString 애니메이션 애니메이션 - 문자열이 사라짐
+ (id)layer
{
Character *layer = [[self alloc] init];
if (layer) {
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"Fabada" size:72]};
layer.symbol = [[NSMutableAttributedString alloc] initWithString:@"X" attributes:attributes];
}
return layer;
}
문자열의 색상을 애니메이트하려면 3 가지 다이내믹 특성이 있습니다.
@interface Character : CALayer
@property (nonatomic, strong) NSMutableAttributedString *symbol;
@property (nonatomic) int red;
@property (nonatomic) int green;
@property (nonatomic) int blue;
@end
@implementation Character
@dynamic red;
@dynamic green;
@dynamic blue;
/* ... */
전경 색상을 설정합니다.
/* Set symbol color */
NSRange range = {0, [self.symbol length]};
UIColor *foreground = [UIColor colorWithRed:self.red /255.0
green:self.green/255.0
blue:self.blue /255.0
alpha:1];
[self.symbol addAttribute:NSForegroundColorAttributeName value:foreground range:range];
CGRect symbolRect; /* The frame */
[self.symbol drawInRect:symbolRect];
문자는 원하는대로 화면에 나타납니다. 하지만 일단 레이어에 CABasicAnimation
을 추가하면 심볼이 사라집니다.
CABasicAnimation *animation = [CABasicAnimation animation];
animation.duration = 10.0;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.delegate = self;
animation.fromValue = [NSNumber numberWithInt:0];
animation.toValue = [NSNumber numberWithInt:255];
[self.character addAnimation:animation forKey:@"blue"];
이 증상은 무엇을 의미합니까? NSAttributedString
속성을 어떻게 애니메이트합니까?