0

我正在尝试为 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?

4

1 回答 1

0

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

于 2012-06-25T18:25:35.067 回答