核心动画隐式动画不会为新添加的子层触发 [英] Core Animation implicit animation doesn't fire for newly added sublayer

查看:36
本文介绍了核心动画隐式动画不会为新添加的子层触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道为什么这行不通。我不能对新添加的子层进行隐式动画处理,直到有人甚至触发它,例如按下按钮或被其他方法调用。即使我认为下面的内容也没有动画。

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;


推荐答案

如果核心动画不会创建隐式动画,层不属于表示层层次结构。

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

尝试以下操作:

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

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

// animation line:
newBar.opacity = 0.5;

这篇关于核心动画隐式动画不会为新添加的子层触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆