Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. //
  2. // SEUIChildManagingViewController.swift
  3. // ThreePanelSplitViewController
  4. //
  5. // Created by Brian Nickel on 6/21/17.
  6. // Copyright © 2017 Brian Nickel. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. public enum AppearanceState {
  12. case disappeared, appeared
  13. case appearing(Bool)
  14. case disappearing(Bool)
  15.  
  16. public var isAnimating: Bool {
  17. switch self {
  18. case .disappeared, .appeared:
  19. return false
  20. case .appearing(let animating):
  21. return animating
  22. case .disappearing(let animating):
  23. return animating
  24. }
  25. }
  26. }
  27.  
  28. open class SEUIChildManagingViewController: UIViewController {
  29.  
  30. private(set) public var childViewControllerContainers: [SEUIChildViewControllerContainer] = []
  31.  
  32. public func add(_ childViewControllerContainer: SEUIChildViewControllerContainer, to superview: UIView) {
  33. childViewControllerContainers.append(childViewControllerContainer)
  34. superview.addSubview(childViewControllerContainer.containerView)
  35. childViewControllerContainer.parentTransitioned(to: appearanceState)
  36. }
  37.  
  38. private(set) public var appearanceState: AppearanceState = .disappeared {
  39. didSet {
  40. for container in childViewControllerContainers {
  41. container.parentTransitioned(to: appearanceState)
  42. }
  43. }
  44. }
  45.  
  46. open override var shouldAutomaticallyForwardAppearanceMethods: Bool {
  47. return false
  48. }
  49.  
  50. open override func viewWillAppear(_ animated: Bool) {
  51. super.viewWillAppear(animated)
  52. appearanceState = .appearing(animated)
  53. }
  54.  
  55. open override func viewDidAppear(_ animated: Bool) {
  56. super.viewDidAppear(animated)
  57. appearanceState = .appeared
  58. }
  59.  
  60. open override func viewWillDisappear(_ animated: Bool) {
  61. super.viewWillDisappear(animated)
  62. appearanceState = .disappearing(animated)
  63. }
  64.  
  65. open override func viewDidDisappear(_ animated: Bool) {
  66. appearanceState = .disappeared
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement