Wil*_*che 1 core-animation objective-c calayer ios
不知道为什么这不起作用.我不能为新添加的子层执行隐式动画,直到有些人甚至触发它就像按下按钮或从另一个方法调用.下面的内容即使我认为我应该也没有动画.它只显示图层的"后"状态.
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;
Run Code Online (Sandbox Code Playgroud)
如果图层不是表示层层次结构的一部分,则Core Animation不会创建隐式动画.
试试这个:
...
[self.insideLayer addSublayer:newBar];
// Tell Core Animation to update the presentation layer hierarchy:
[CATransaction flush];
// animation line:
newBar.opacity = 0.5;
Run Code Online (Sandbox Code Playgroud)