iOS Segue - Left to Right -

前端 未结 11 1002
旧巷少年郎
旧巷少年郎 2020-11-30 20:40

I\'ve read the other posts on segues but none solve my question.

Simply put, my ViewControllers are ordered, like a book. I want backward transitions (

11条回答
  •  被撕碎了的回忆
    2020-11-30 21:15

    You can use of the predeclared type of transition in transitionWithView method

    UIView.transitionWithView(self.window!, duration: 0.5, options:.TransitionFlipFromLeft, animations: { () -> Void in
                self.window!.rootViewController = mainVC
                }, completion:nil)
    

    I guess .TransitionFlipFromLeft is the desired one

    To complete the task, drag a new view controller to your storyboard and name it with some id. This is going to be the destination of the transition.

    then instantiate this view controller from code

    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
    let mainVC = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
    

    You can do this either inside the IBAction or for example in ViewDidLoad but probably IBAction will be the better choice. Pay attention to type the correct identifiers for both storyboard and view controller. Also, you have to declare your appDelegate instance. Here is the implemented IBAction

    @IBAction func push(sender: UIButton) {
    
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let mainVC = storyboard.instantiateViewControllerWithIdentifier("secondVC") as! UIViewController
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    
        UIView.transitionWithView(appDelegate.window!, duration: 0.5, options: .TransitionFlipFromLeft , animations: { () -> Void in
            appDelegate.window!.rootViewController = mainVC
            }, completion:nil)
    }
    

    If this is not what you have expected, probably you might want to make a custom animation. This article is really helpful : http://mathewsanders.com/animated-transitions-in-swift/

提交回复
热议问题