DetailViewController.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // DetailViewController.swift
  3. // SwiftCharts
  4. //
  5. // Created by ischuetz on 20/04/15.
  6. // Copyright (c) 2015 ivanschuetz. All rights reserved.
  7. //
  8. import UIKit
  9. class DetailViewController: UIViewController, UISplitViewControllerDelegate {
  10. @IBOutlet weak var detailDescriptionLabel: UILabel!
  11. lazy private(set) var chartFrame: CGRect! = {
  12. CGRect(x: 0, y: 80, width: self.view.frame.size.width, height: self.view.frame.size.height - 80)
  13. }()
  14. var detailItem: Example? {
  15. didSet {
  16. configureView()
  17. }
  18. }
  19. var currentExampleController: UIViewController?
  20. func configureView() {
  21. if let example: Example = detailItem {
  22. switch example {
  23. case .helloWorld:
  24. setSplitSwipeEnabled(true)
  25. showExampleController(HelloWorld())
  26. case .bars:
  27. setSplitSwipeEnabled(true)
  28. showExampleController(BarsExample())
  29. case .stackedBars:
  30. setSplitSwipeEnabled(true)
  31. showExampleController(StackedBarsExample())
  32. case .barsPlusMinus:
  33. setSplitSwipeEnabled(true)
  34. showExampleController(BarsPlusMinusWithGradientExample())
  35. case .groupedBars:
  36. setSplitSwipeEnabled(true)
  37. showExampleController(GroupedBarsExample())
  38. case .barsStackedGrouped:
  39. setSplitSwipeEnabled(true)
  40. showExampleController(GroupedAndStackedBarsExample())
  41. case .scatter:
  42. setSplitSwipeEnabled(true)
  43. showExampleController(ScatterExample())
  44. case .notifications:
  45. setSplitSwipeEnabled(true)
  46. showExampleController(NotificationsExample())
  47. case .target:
  48. setSplitSwipeEnabled(true)
  49. showExampleController(TargetExample())
  50. case .areas:
  51. setSplitSwipeEnabled(true)
  52. showExampleController(AreasExample())
  53. case .rangedAxis:
  54. setSplitSwipeEnabled(true)
  55. showExampleController(RangedAxisExample())
  56. case .bubble:
  57. setSplitSwipeEnabled(true)
  58. showExampleController(BubbleExample())
  59. case .combination:
  60. setSplitSwipeEnabled(true)
  61. showExampleController(BarsPlusMinusAndLinesExample())
  62. case .coords:
  63. setSplitSwipeEnabled(true)
  64. showExampleController(CoordsExample())
  65. case .tracker:
  66. setSplitSwipeEnabled(false)
  67. showExampleController(TrackerExample())
  68. case .multiTracker:
  69. setSplitSwipeEnabled(false)
  70. showExampleController(MultiTrackerExample())
  71. case .equalSpacing:
  72. setSplitSwipeEnabled(true)
  73. showExampleController(EqualSpacingExample())
  74. case .customUnits:
  75. setSplitSwipeEnabled(true)
  76. showExampleController(CustomUnitsExample())
  77. case .multival:
  78. setSplitSwipeEnabled(true)
  79. showExampleController(MultipleLabelsExample())
  80. case .multiAxis:
  81. setSplitSwipeEnabled(true)
  82. showExampleController(MultipleAxesExample())
  83. case .multiAxisInteractive:
  84. setSplitSwipeEnabled(true)
  85. showExampleController(MultipleAxesInteractiveExample())
  86. case .candleStick:
  87. setSplitSwipeEnabled(true)
  88. showExampleController(CandleStickExample())
  89. case .cubiclines:
  90. setSplitSwipeEnabled(true)
  91. showExampleController(CubicLinesExample())
  92. case .cubiclinesWithGradient:
  93. setSplitSwipeEnabled(true)
  94. showExampleController(CubicLinesWithGradientExample())
  95. case .notNumeric:
  96. setSplitSwipeEnabled(true)
  97. showExampleController(NotNumericExample())
  98. case .candleStickInteractive:
  99. setSplitSwipeEnabled(false)
  100. showExampleController(CandleStickInteractiveExample())
  101. case .trendline:
  102. setSplitSwipeEnabled(true)
  103. showExampleController(TrendlineExample())
  104. }
  105. }
  106. }
  107. fileprivate func showExampleController(_ controller: UIViewController) {
  108. if let currentExampleController = currentExampleController {
  109. currentExampleController.removeFromParent()
  110. currentExampleController.view.removeFromSuperview()
  111. }
  112. addChild(controller)
  113. view.addSubview(controller.view)
  114. currentExampleController = controller
  115. }
  116. fileprivate func setSplitSwipeEnabled(_ enabled: Bool) {
  117. if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad {
  118. let splitViewController = UIApplication.shared.delegate?.window!!.rootViewController as! UISplitViewController
  119. splitViewController.presentsWithGesture = enabled
  120. }
  121. }
  122. }