创建图层后不会触发CABasicAnimation

时间:2014-06-25 02:16:02

标签: ios objective-c ios7 core-animation

我有CALayer子类。创建图层后,我想为图层的affineTransform设置动画,但没有成功。设置了新值,但更改未设置动画。如果我在1秒后触发动画,一切都很完美。

        RCLClockDialLayer *layer = [RCLClockDialLayer layer];
        layer.frame = CGRectMake(center.x, center.y, 2, self.radius);

        layer.center = center;
        layer.radius = self.radius;
        layer.width = width;
        layer.backgroundColor = [UIColor blackColor].CGColor;
        layer.color = [UIColor whiteColor];

        layer.affineTransform = CGAffineTransformRotate(layer.affineTransform, RCLDegreesToRadians(270));

        [self addSubLayer:layer];

        CGAffineTransform transform = CGAffineTransformIdentity;
        transform = CGAffineTransformRotate(transform, RCLDegreesToRadians(80));

        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"affineTransform"];
        animation.duration = .5;
        animation.fromValue = [layer valueForKey:@"affineTransform"];
        animation.toValue = [NSValue valueWithCGAffineTransform:transform];
        animation.fillMode = kCAFillModeForwards;
        animation.cumulative = YES;
        animation.removedOnCompletion = NO;
        layer.affineTransform = transform;

        [layer addAnimation:animation forKey:@"affineTransform"];

这是我的代码。我尝试了很多不同的解决方案但没有任何效果有人知道这是什么原因吗?

0 个答案:

没有答案