CABasicAnimation with zero duration
Asked Answered
T

1

13

I have a CALayer in an AVMutableComposition that is faded in, should stay on screen for a while and then disappear. The problem is, it should disappear without an animation, but CABasicAnimation has a minimum duration of 0.25 seconds.

How would can I achieve to set the opacity of the layer after a given time without animating it?

Tallith answered 29/8, 2013 at 9:25 Comment(5)
You can try the following way [self performSelector:<your selector> withObject:<object if you want to pass anything> afterDelay:<time delay>];Gonocyte
@Bala, I don't think this would really work because the animation has to be inside a video I guess. Right @SwissDude?Ci
Hey, did you end up solving this? I have the same problemCharybdis
@bcattle: I actually never did. I just ditched the animation and put another layer over the whole composition that I fade in and out...Tallith
Gotcha. I think the real solution for zero-length transitions is implementing a custom video compositor class as described in this great @rob mayoff answer. The example (overlaying one video over another) is totally unrelated, but you get raw access to the pixels and can therefore do whatever you want. The downside is you lose the built-in Core Animation machinery. Thanks for the followup!Charybdis
K
4

Encapsulating the removal of the layer into a Core Animation transaction where you disable animations:

[CATransaction begin];
[CATransaction setDisableActions:YES];
// remove the layer from its hierarchy
[CATransaction commit];

or the same in Swift:

CATransaction.begin()
CATransaction.setDisableActions(true)
// remove the layer from its hierarchy
CATransaction.commit()
Katerinekates answered 6/7, 2018 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.