Skip to content

Instantly share code, notes, and snippets.

@sgoodwin
Last active August 29, 2015 14:19
Show Gist options
  • Save sgoodwin/2df91dc1974c49c01f8d to your computer and use it in GitHub Desktop.
Save sgoodwin/2df91dc1974c49c01f8d to your computer and use it in GitHub Desktop.
class ForwardSegue: UIStoryboardSegue {
override func perform() {
let source = self.sourceViewController as! UIViewController
let destination = self.destinationViewController as! UIViewController
let window = UIApplication.sharedApplication().keyWindow!
window.insertSubview(destination.view, aboveSubview: source.view)
destination.animateIn()
source.animateOut {
// To fix the issue with unbalanced viewwillappear/disappear calls
destination.viewWillDisappear(true)
destination.viewDidDisappear(true)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
source.presentViewController(destination, animated: false, completion: nil)
})
}
}
}
class BackSegue: UIStoryboardSegue {
override func perform() {
let source = self.sourceViewController as! UIViewController
let destination = self.destinationViewController as! UIViewController
let window = UIApplication.sharedApplication().keyWindow!
destination.dismissViewControllerAnimated(false, completion: { () -> Void in
window.insertSubview(source.view, aboveSubview: destination.view)
source.animateOut {
source.view.removeFromSuperview()
}
destination.animateIn()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment