Created
June 7, 2015 14:57
-
-
Save MickaelCruzDB/35f353fbab48816abbaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // OutletRetention | |
| // | |
| // Created by Thomas Krajacic on 8.3.2015. | |
| // Copyright (c) 2015 Thomas Krajacic. All rights reserved. | |
| // | |
| import Cocoa | |
| class ViewController: NSViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view. | |
| } | |
| override var representedObject: AnyObject? { | |
| didSet { | |
| // Update the view, if already loaded. | |
| } | |
| } | |
| @IBAction func present(sender: NSButton) { | |
| let storyboard = NSStoryboard(name: "Main", bundle: nil) | |
| switch sender.title { | |
| case "A": | |
| let vc = storyboard?.instantiateControllerWithIdentifier("A") as! NSViewController | |
| self.showViewController(vc) | |
| case "B": | |
| let vc = storyboard?.instantiateControllerWithIdentifier("B") as! NSViewController | |
| self.showViewController(vc) | |
| default: break | |
| } | |
| } | |
| let animator = FadeTransitionAnimator() | |
| let swipe = FadeTransitionAnimator() | |
| func showViewController(viewController: NSViewController) { | |
| // hide all others | |
| self.dismissAllViewControllers() | |
| self.addChildViewController(viewController) | |
| // present new viewcontroller | |
| presentViewController(viewController, animator: swipe) | |
| } | |
| func dismissAllViewControllers() { | |
| if let previousVC = self.childViewControllers.last as? NSViewController { | |
| self.dismissViewController(previousVC) | |
| previousVC.removeFromParentViewController() | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment