核心animation隐式animation不会为新添加的子层触发

不知道为什么这不起作用。 我不能为新添加的子层做隐式animation,除非有人甚至像触发button或从另一个方法中调用它。 即使我认为我应该这样下面这个不animation。 它只是显示图层的“之后”状态。

CAGradientLayer *newBar = [CAGradientLayer layer]; CGFloat barHeight = ((pair.amount.floatValue/self.model.maxModelValue.floatValue)*maxBarHeight); newBar.bounds=R(0,0,self.barWidth,0); newBar.anchorPoint=P(0, 1); newBar.position=P((i*barSpacing), self.insideLayer.bounds.size.height); newBar.backgroundColor=self.lowerColor.CGColor; newBar.colors=[NSArray arrayWithObjects:(id)self.upperColor.CGColor, self.lowerColor.CGColor, nil]; newBar.cornerRadius=self.cornerRadius; newBar.opacity=1.0; [self.insideLayer addSublayer:newBar]; //animation line: newBar.opacity=0.5; 

如果图层不是表示层层次结构的一部分,则Core Animation不会创build隐式animation。

尝试这个:

 ... [self.insideLayer addSublayer:newBar]; // Tell Core Animation to update the presentation layer hierarchy: [CATransaction flush]; // animation line: newBar.opacity = 0.5;