Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CALayer上CABasicAnimation变换的问题_Ios_Cocoa_Core Animation_Calayer - Fatal编程技术网

Ios CALayer上CABasicAnimation变换的问题

Ios CALayer上CABasicAnimation变换的问题,ios,cocoa,core-animation,calayer,Ios,Cocoa,Core Animation,Calayer,我正在尝试在CAGradientLayer上设置变换动画,但是无论我做什么,我似乎都无法实现更改。运行此代码后,该层仍然不可见(即scale.y仍然为0.0f) } 有人知道为什么这不会导致层的比例.y被设置为1吗?我似乎记得使用0的比例会导致层塌陷为零大小。尝试使用.001的大小而不是0。这是因为CALayer没有名为transform.scale.y@ZeusAlexander的属性,但它是制作动画的完全有效的关键点路径。再读一遍。将self.layer投射到渐变层,然后再设置动画,这不是有

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

}


有人知道为什么这不会导致层的比例.y被设置为1吗?

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

这是因为
CALayer
没有名为
transform.scale.y
@ZeusAlexander的属性,但它是制作动画的完全有效的关键点路径。再读一遍。将self.layer投射到渐变层,然后再设置动画,这不是有点奇怪吗?我想你应该把自己的图层添加到它上面,并通过ivar引用它。如果在doAnimation中设置断点并检查状态,会发生什么?如果改为设置其他属性的动画,会发生什么?注意:显式动画永远不会更改实际值,因此在动画之后,该值将显示为跳回其原始状态,这是您看到的吗?我现在已经在一个子层中尝试了这一点,设置removedOnCompletion=NO以及将fillMode设置为forward,会产生相同的结果。如果在第一种方法中注释掉该行,在该方法中我显式地设置了变换,然后将动画更改为缩放为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"];
}