简体   繁体   English

是否可以创建从右到左过渡的自定义Segue

[英]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. 我正在使用Swift创建一个iOS应用程序,我想创建从右到左过渡的自定义segue。 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! 谢谢!

Try this 尝试这个

class RightToLeftSegue : UIStoryboardSegue {

     override func perform() {

         guard let navigationController = sourceViewController.navigationController else { return }

         sourceViewController.view.superview?.addSubview(destinationViewController.view)

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

         UIView.animateWithDuration(0.5,
         animations: {
             self.sourceViewController.view.frame = CGRectOffset(frame, frame.size.width, 0.0)
             self.destinationViewController.view.frame = frame
         })
         { (finished: Bool) in 
             navigationController.rootViewController = self.destinationViewController
         }

    }

}

EDIT 编辑

Or this! 或这个!

class RightToLeftSegue : UIStoryboardSegue {

    override func perform() {
        sourceViewController.navigationController?.viewControllers = [destinationViewController, sourceViewController]
        sourceViewController.navigationController?.popViewControllerAnimated(true)
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM