gpt4 book ai didi

objective-c - 核心动画隐式动画不会为新添加的子层触发

转载 作者:行者123 更新时间:2023-12-01 18:00:39 27 4
gpt4 key购买 nike

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

    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将不会创建隐式动画。

尝试这个:

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

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

// animation line:
newBar.opacity = 0.5;

关于objective-c - 核心动画隐式动画不会为新添加的子层触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com