2015-08-04 1 views
0

Je veux changer la transition de mon code de gauche à droite, mais ce CustomeSegue montre jusqu'à vers le bas seulement, merci !!!Besoin de changer la transition de segue de gauche à droite, puis de droite à gauche

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) 
     } 
    } 

} 

Répondre

2

De votre code:

ne devriez-vous pas utiliser la largeur et non la hauteur?

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

également ici

// 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) 
    } 
1

Ajoutez ce code à votre source View Controller sur l'action du bouton à partir de laquelle vous devez aller à gauche.

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() 
    } 

Dans votre destination Voir contrôleur ajoutez le code suivant

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() 
     } 
    } 

Ajoutez ce code en vous viewWillAppear destination

override func viewWillAppear(animated: Bool) { 

     if TransistionFromSourceVC 
     { 
      ViewAndAnimateIt() 
     } 

    } 

Effectuez les modifications respectives de la source et la destination viewController.

+0

J'utilise le geste de balayage pour naviguer entre viewControllers, alors comment puis-je modifier cette :) merci !! –

+1

Vous pouvez appeler la fonction performanimation dans le mouvement de balayage. – Karlos

+1

Vérifiez le lien suivant, il sera utile http://stackoverflow.com/questions/28675209/how-to-call-gesture-tap-on-uiview-programmatically-in-swift – Karlos