Custom Segue With CATransition

546 views Asked by At

I wrote the following code to have a transition from right to left from one to another view controller. But the new view controller just appears without animation.

override func perform() {

var sourceViewController = self.sourceViewController as! UIViewController
var destinationViewController = self.destinationViewController as! UIViewController

var transition: CATransition = CATransition()

transition.duration = 1.25
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight

destinationViewController.view.layer.addAnimation(transition, forKey: "kCATransition")
sourceViewController.presentViewController(destinationViewController, animated: false, completion: nil)

}

I just can't find any mistake. Can anyone find one? Am I missing something simple?

Thank you in advance

1

There are 1 answers

0
user2731717 On

change this code:

destinationViewController.view.layer.addAnimation(transition, forKey: "kCATransition")

to the new one:

destinationViewController.view.window!.layer.addAnimation(transition, forKey: "kCATransition")