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?

clemens
  • 16,716
  • 11
  • 50
  • 65
Swissdude
  • 3,486
  • 3
  • 35
  • 68
  • You can try the following way [`[self performSelector: withObject: afterDelay: – Bala Aug 31 '13 at 13:28
  • @Bala, I don't think this would really work because the animation has to be inside a video I guess. Right @SwissDude? – SarpErdag Feb 03 '14 at 11:11
  • 2
    Hey, did you end up solving this? I have the same problem – bcattle Apr 22 '15 at 23:36
  • 1
    @bcattle: I actually never did. I just ditched the animation and put another layer over the whole composition that I fade in and out... – Swissdude Apr 24 '15 at 19:07
  • 1
    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](http://stackoverflow.com/a/28260671/1161906). 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! – bcattle Apr 24 '15 at 19:30

1 Answers1

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()
clemens
  • 16,716
  • 11
  • 50
  • 65