Iphone 我的UILabel上没有发生动画

Iphone 我的UILabel上没有发生动画,iphone,objective-c,core-animation,Iphone,Objective C,Core Animation,我为一些图像编写了一些动画,效果很好。这几乎是同样的动画,但这一次在一个可复制的。但似乎什么都没有。标签会绘制,但当我调用动画方法时,文本不会更改/移动 -(void) bounceText { NSLog(@"Bounce Text"); CABasicAnimation *grow; grow = [CABasicAnimation animationWithKeyPath:@"growText"]; grow.timingFunction = [CAMediaTimingFunction

我为一些图像编写了一些动画,效果很好。这几乎是同样的动画,但这一次在一个可复制的。但似乎什么都没有。标签会绘制,但当我调用动画方法时,文本不会更改/移动

-(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;   
    }
}
}
是否标签不能转换

玩了一个小时,什么也没发生-

谢谢
-代码

这里的主要问题是您没有指定要设置动画的属性。CAPropertyAnimation的文档说明了animationWithKeyPath:method的以下内容:

要设置动画的特性的关键路径

我不是100%确定你想用你的动画实现什么,但是你有以下代码:

fade = [CABasicAnimation animationWithKeyPath:@"fade"];
    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"];
这应该是:

fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
因为您希望影响标签的不透明度,使其淡入或淡出。因此,要使标签在5秒内从0.5到1.0的不透明度淡入,可以使用以下代码:

fade = [CABasicAnimation animationWithKeyPath:@"fade"];
    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"];

这里的主要问题是您没有指定要设置动画的属性。CAPropertyAnimation的文档说明了animationWithKeyPath:method的以下内容:

要设置动画的特性的关键路径

我不是100%确定你想用你的动画实现什么,但是你有以下代码:

fade = [CABasicAnimation animationWithKeyPath:@"fade"];
    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"];
这应该是:

fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
因为您希望影响标签的不透明度,使其淡入或淡出。因此,要使标签在5秒内从0.5到1.0的不透明度淡入,可以使用以下代码:

fade = [CABasicAnimation animationWithKeyPath:@"fade"];
    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"];

你的方法被调用了吗?它在主线程上被调用了吗?是的,它被调用了。你可以从NSLogIs中看到你的方法被调用了吗?它被调用了吗?是的,它被调用了。你可以从NSLogfade中看到它只是一个名称。据我所知,你可以调用这个蛋糕,它不会有任何区别。你在方法animationWithKeyPath:中指定的关键路径对动画至关重要。关键路径定义了要设置动画的图层特性。您在addAnimation:forKey:方法中指定的关键点只是一个名称,是的,如果您愿意,可以将其称为“蛋糕”。fade只是一个名称。据我所知,你可以调用这个蛋糕,它不会有任何区别。你在方法animationWithKeyPath:中指定的关键路径对动画至关重要。关键路径定义了要设置动画的图层特性。您在addAnimation:forKey:方法中指定的关键点只是一个名称,是的,如果您愿意,可以将其称为“蛋糕”。