-1

My goal is to perform a flip-animation from view1 to view2 and vice versa. I only want to flip the views not the whole viewController

Set up as follows: i have a view controller (fromViewController) in my storyboard embedded in a navigationController. I drew a segue to a second view controller (toViewController) and made it a custom segue. Now i want to add a flip animation to flip the views of the view controllers from left to right and right to left. The forward animation already works (from fromViewController to toViewController) but he backward animation does not work. I checked a lot of similar questions here but i couldn't find an answer that fit my needs.

I hope someone can help me out of this.

The class for the custom segue is FlipSegue. here is my code:

import UIKit

extension UIViewController{
    var isVisible: Bool{
        return self.isViewLoaded && self.view.window != nil
    }
}

class FlipSegue: UIStoryboardSegue {

    override func perform() {
        let fromViewController = self.source
        let toViewController = self.destination

        if fromViewController.isVisible{
            UIView.transition(from: fromViewController.view, to: toViewController.view, duration: 1, options: .transitionFlipFromLeft, completion: nil)
        }
        else{
             UIView.transition(from: toViewController.view, to: fromViewController.view, duration: 1, options: .transitionFlipFromRight, completion: nil)
        }
    }
}

FYI: The toViewController is not part of the NavigationController.

EDIT: I perform the segue by tapping on a UIBarButton on the left side of the navigation controller. The Button is calling the perform function in the FlipSegue class. Maybe the problem is that the toViewController is not part of the navigation stack? So i added it to the navigation stack and then i got a back button and i could return to the fromViewController with the standard animation, but this is not what i wanted.

user1895268
  • 1,559
  • 3
  • 11
  • 23

1 Answers1

0

I haven't tried this, but you should probably use from:fromViewcontroller.view in both cases, since in a back segue, from is still the starting VC.

Duncan C
  • 128,072
  • 22
  • 173
  • 272