我为一些图片写了一些动画,但它确实有效。它几乎是相同的动画,但这次是在UILable上。但似乎没有任何东西。标签绘制但是当我调用动画方法时,文本不会改变/移动。
-(void) bounceText
{
NSLog(@"Bounce Text");
CABasicAnimation *grow;
grow = [CABasicAnimation animationWithKeyPath:@"growText"];
grow.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear];
grow.toValue = [NSNumber numberWithFloat:3.0];
grow.fromValue = [NSNumber numberWithFloat:0.1];
grow.repeatCount = 10;
grow.fillMode = kCAFillModeForwards;
grow.removedOnCompletion = YES;
grow.duration = 5.0;
grow.autoreverses = NO;
grow.delegate = self;
CABasicAnimation *fade;
fade = [CABasicAnimation animationWithKeyPath:@"fade"];
fade.fromValue = [NSNumber numberWithFloat:0.5];
fade.toValue = [NSNumber numberWithFloat:1.0];
fade.duration = 5.0;
CALayer *layer = [CALayer layer];
hintsLabel.layer.transform=CATransform3DTranslate(CATransform3DIdentity, 0, 0,50);
[CATransaction begin];
[hintsLabel.layer addSublayer:layer];
[hintsLabel.layer addAnimation:grow forKey:@"growTheText"];
[layer addAnimation:fade forKey:@"fadeText"];
[CATransaction commit];
}
调用方法并在标签上添加文字
-(void) drawHints
{
if (gameState == SHOWCARD)
{
hintsLabel.layer.zPosition = 5;
hintsLabel.text = @"It's your turn, select a button!";
if (!bounce)
{
[self bounceText];
bounce = YES;
}
}
}
标签是否无法转换?
玩了一个小时并没有发生任何事情 - .-
由于 -code
答案 0 :(得分:4)
这里的主要问题是您没有指定要设置动画的属性。 CAPropertyAnimation的文档为animationWithKeyPath:方法声明了以下内容:
要动画的属性的关键路径。
我不是100%肯定你想要用你的动画实现什么,但你有以下代码:
fade = [CABasicAnimation animationWithKeyPath:@"fade"];
应该是:
fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
因为您希望影响标签的不透明度以使其淡入或淡出。因此,要使您的标签在5秒内从0.5到1.0的不透明度淡入,您将使用以下代码:
CABasicAnimation *fade;
fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
fade.fromValue = [NSNumber numberWithFloat:0.5];
fade.toValue = [NSNumber numberWithFloat:1.0];
fade.duration = 5.0;
[hintsLabel.layer addAnimation:fade forKey:@"fade"];