Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // OutletRetention
  4. //
  5. // Created by Thomas Krajacic on 8.3.2015.
  6. // Copyright (c) 2015 Thomas Krajacic. All rights reserved.
  7. //
  8.  
  9. import Cocoa
  10.  
  11. class ViewController: NSViewController {
  12.  
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15.  
  16. // Do any additional setup after loading the view.
  17. }
  18.  
  19. override var representedObject: AnyObject? {
  20. didSet {
  21. // Update the view, if already loaded.
  22. }
  23. }
  24.  
  25. @IBAction func present(sender: NSButton) {
  26.  
  27. let storyboard = NSStoryboard(name: "Main", bundle: nil)
  28.  
  29. switch sender.title {
  30. case "A":
  31. let vc = storyboard?.instantiateControllerWithIdentifier("A") as! NSViewController
  32. self.showViewController(vc)
  33.  
  34. case "B":
  35. let vc = storyboard?.instantiateControllerWithIdentifier("B") as! NSViewController
  36. self.showViewController(vc)
  37.  
  38. default: break
  39. }
  40. }
  41.  
  42. let animator = FadeTransitionAnimator()
  43.  
  44. let swipe = FadeTransitionAnimator()
  45.  
  46. func showViewController(viewController: NSViewController) {
  47. // hide all others
  48. self.dismissAllViewControllers()
  49.  
  50.  
  51. self.addChildViewController(viewController)
  52. // present new viewcontroller
  53. presentViewController(viewController, animator: swipe)
  54. }
  55.  
  56. func dismissAllViewControllers() {
  57. if let previousVC = self.childViewControllers.last as? NSViewController {
  58. self.dismissViewController(previousVC)
  59. previousVC.removeFromParentViewController()
  60. }
  61.  
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement