0

I want change my code's transition from left to right , but this CustomeSegue show up to down only, Thank you !!!

class FirstCustomSegue: UIStoryboardSegue {

     override func perform() {
         // Assign the source and destination views to local variables.
        var firstVCView = self.sourceViewController.view as UIView!
        var secondVCView = self.destinationViewController.view as UIView!

         // Get the screen width and height.
        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height

         // Specify the initial position of the destination view.
        secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)

         // Access the app's key window and insert the destination view above the current (source) one.
        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVCView, aboveSubview: firstVCView)


         // Animate the transition.
        UIView.animateWithDuration(0.4, animations: { () -> Void in
            firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
            secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

            }) { (Finished) -> Void in
                self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                    animated: false,
                    completion: nil)
        }
    }

}
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Mudith Chathuranga Silva
  • 7,253
  • 2
  • 50
  • 58

2 Answers2

2

From your code:

shouldn't you using the width not the height?

    // Specify the initial position of the destination view.
    secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)

Also here

    // Animate the transition.
    UIView.animateWithDuration(0.4, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
        secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)

        }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                animated: false,
                completion: nil)
    }
TorIsHere
  • 119
  • 2
  • 8
1

Add this code to your source View Controller on the button action from where you have to go left.

func performAnimation()
    {
        var mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        // Identifier name for the navigation controller
        var initialNavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController

        //Identifier name for the view controller
        var  mainVC = mainStoryboard.instantiateViewControllerWithIdentifier("startingViewController") as! DestinationViewControllername

        initialNavigationController.viewControllers = [mainVC]


        self.presentViewController(initialNavigationController,  animated: false, completion: nil)
        (mainVC as DestinationViewControllername).DestinationRespondSelector()
    }

In your Destination View controller add the following code

var TransistionFromSourceVC = false
    func DestinationRespondSelector()
    {
        TransistionFromSourceVC = true
    }

    func ViewAndAnimateIt()
    {
        println("here")
        TransistionFromSourceVC = false

        var mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        // Identifier name for the navigation controller
        var mainNavigationController = mainStoryBoard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController
         //Identifier name for the view controller
        var SourceVC = mainStoryBoard.instantiateViewControllerWithIdentifier("SourceViewController") as! SourceVC
        mainNavigationController.viewControllers = [SourceVC]

        self.view.addSubview(mainNavigationController.view)
        self.view.bringSubviewToFront(mainNavigationController.view)

        UIView.animateWithDuration(0.3, animations: {

            mainNavigationController.view.frame.origin.x += self.view.frame.width

            }) { (finished) -> Void in

                mainNavigationController.view.removeFromSuperview()
        }
    }

Add this code in you destination viewWillappear

  override func viewWillAppear(animated: Bool) {

        if TransistionFromSourceVC
        {
            ViewAndAnimateIt()
        }

    }

Make the respective changes for the source and destination viewController.

Karlos
  • 1,653
  • 18
  • 36