Core Animation implicit animation doesn't fire for newly added sublayer

蹲街弑〆低调 提交于 2020-01-14 03:43:27

问题


Don't know why this doesn't work. I can't do implicit animation for a newly added sublayer until some even triggers it like a button push or being called from another method. This here below doesn't animate even though I think i should. It just shows the 'after' state of the layer.

    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;

回答1:


Core Animation won't create an implicit animation if the layer isn't part of the presentation layer hierarchy.

Try this:

...
[self.insideLayer addSublayer:newBar];

// Tell Core Animation to update the presentation layer hierarchy:
[CATransaction flush];

// animation line:
newBar.opacity = 0.5;


来源:https://stackoverflow.com/questions/10456022/core-animation-implicit-animation-doesnt-fire-for-newly-added-sublayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!