Show animation when addsubview

If you want to add a subview with animation, try this simple snippet:

PS: Replace myView with the name of the view you want to replace.

CATransition *applicationLoadViewIn =[CATransition animation];
[applicationLoadViewIn setDuration:duration];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];

One thought on “Show animation when addsubview”

  1. De gran ayuda este post. Muchas gracias. Os dejo una actualizaciĆ³n para Swift 4.0. Un saludo.

    let animation = CATransition()
    animation.duration = 0.5
    animation.type = kCATransitionReveal
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
    myView.layer.add(transition, forKey: kCATransitionReveal)

Leave a Reply

Your email address will not be published. Required fields are marked *