在CALayer上使用CABasicAnimation转换的麻烦

时间:2012-06-24 01:57:43

标签: ios cocoa core-animation calayer

我试图在CAGradientLayer上设置变换动画,但无论我做什么,我似乎都无法做出改变。此代码运行后,图层仍然不可见(即scale.y仍为0.0f)。

@implementation NickView

+(Class) layerClass {
    return [CAGradientLayer class];
}

- (void) didMoveToWindow {    
    self.backgroundColor = [UIColor clearColor];

    CAGradientLayer* gLayer = (CAGradientLayer*)self.layer;

    [gLayer setColors:
     [NSArray arrayWithObjects:
      (id) [UIColor blackColor].CGColor,
      (id) [UIColor redColor].CGColor,
      (id) [UIColor blackColor].CGColor,
      nil]];

    gLayer.transform = CATransform3DMakeScale(1.0, 0.0f, 1.0f);
    [self performSelector:@selector(doAnimation) withObject:nil afterDelay:3.0f];
}

- (void) doAnimation  {
    CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    a.delegate = self;
    a.duration = 5.0f;
    a.toValue = [NSNumber numberWithFloat:1.0f];
    [self.layer addAnimation:a forKey:@"anim"];
}

}

有谁知道为什么这不会导致图层的scale.y被动画回1?

1 个答案:

答案 0 :(得分:0)

我似乎记得使用0比例会导致图层折叠为零。尝试使用.001而不是0的大小。