Dave Dave - 2 years ago 83
Swift Question

Is it possible to create Custom Segue which transitions from right to left

I'm creating an iOS app with Swift and I'd like to create custom segue which transitions from right to left. The default transition way is from left to right but I do need to have the opposite way of transition. I just wrote the code like this.

class RightToLeftSegue: UIStoryboardSegue {

override func perform() {
let sourceViewController = self.sourceViewController
let destinationViewController = self.destinationViewController

let window = UIApplication.sharedApplication().keyWindow
window!.rootViewController = destinationViewController
window!.rootViewController = sourceViewController
UIView.transitionWithView(window!, duration: 0.5, options: .TransitionFlipFromLeft, animations: { window!.rootViewController = destinationViewController }, completion: { (finished: Bool) in })

But this just transitions flipping move. Any way I can do this? Thanks!

Answer Source

Try this

class RightToLeftSegue : UIStoryboardSegue {

     override func perform() {

         if let window = UIApplication.sharedApplication().keyWindow as? UIWindow { 

             window.rootViewController = sourceViewController

             let frame = sourceViewController.view.frame
             destinationViewController.view.frame = CGRectOffset(frame, frame.size.width, 0.0)

             animations: {
                 sourceViewController.view.frame = CGRectOffset(frame, -frame.size.width, 0.0)
                 destinationViewController.view.frame = frame
             { (finished: Bool) in 
                 window.rootViewController = destinationViewController



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download