Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. class BoardingPageViewController: UIPageViewController {
  2.  
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5. dataSource = self
  6. delegate = self
  7. setViewControllers([getStepOne()], direction: .forward, animated: false, completion: nil)
  8. }
  9.  
  10. override var preferredStatusBarStyle: UIStatusBarStyle {
  11. return .lightContent
  12. }
  13.  
  14. func getStepOne() -> BoardView1ViewController {
  15. return storyboard!.instantiateViewController(withIdentifier: "BoardView1") as! BoardView1ViewController
  16. }
  17.  
  18. func getStepTwo() -> BoardView2ViewController {
  19. return storyboard!.instantiateViewController(withIdentifier: "BoardView2") as! BoardView2ViewController
  20. }
  21.  
  22. func getStepThree() -> BoardView3ViewController {
  23. return storyboard!.instantiateViewController(withIdentifier: "BoardView3") as! BoardView3ViewController
  24. }
  25. func getStepFour() -> BoardView4ViewController {
  26. return storyboard!.instantiateViewController(withIdentifier: "BoardView4") as! BoardView4ViewController
  27. }
  28. func getStepFive() -> BoardView5ViewController {
  29. return storyboard!.instantiateViewController(withIdentifier: "BoardView5") as! BoardView5ViewController
  30. }
  31. }
  32.  
  33. extension BoardingPageViewController : UIPageViewControllerDataSource {
  34.  
  35. func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
  36. if viewController.isKind(of: BoardView5ViewController.self) {
  37. // 5 -> 4
  38. return getStepFour()
  39. } else if viewController.isKind(of: BoardView4ViewController.self) {
  40. // 4 -> 3
  41. return getStepThree()
  42. } else if viewController.isKind(of: BoardView3ViewController.self) {
  43. // 3 -> 2
  44. return getStepTwo()
  45. } else if viewController.isKind(of: BoardView2ViewController.self) {
  46. // 2 -> 1
  47. return getStepOne()
  48. } else {
  49. // 0 -> end of the road
  50. return nil
  51. }
  52. }
  53.  
  54. func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
  55. if viewController.isKind(of: BoardView1ViewController.self) {
  56. // 0 -> 1
  57. return getStepTwo()
  58. } else if viewController.isKind(of: BoardView2ViewController.self) {
  59. // 1 -> 2
  60. return getStepThree()
  61. } else if viewController.isKind(of: BoardView3ViewController.self) {
  62. // 1 -> 2
  63. return getStepFour()
  64. } else if viewController.isKind(of: BoardView4ViewController.self) {
  65. // 1 -> 2
  66. return getStepFive()
  67. } else {
  68. // 2 -> end of the road
  69. return nil
  70. }
  71. }
  72.  
  73. func presentationCount(for pageViewController: UIPageViewController) -> Int {
  74. return 5
  75. }
  76.  
  77. func presentationIndex(for pageViewController: UIPageViewController) -> Int {
  78. return 0
  79. }
  80.  
  81. }
  82.  
  83. extension BoardingPageViewController : UIPageViewControllerDelegate {
  84.  
  85. }
  86.  
  87. override func viewDidAppear(_ animated: Bool) {
  88. chainAni = true
  89. ani0()
  90. }
  91.  
  92. func ani0() {
  93. if chainAni != true {
  94. return
  95. }
  96. UIView.animate(withDuration: 1, delay: 1, animations: {
  97. self.handPic.alpha = 1
  98. }) { (false) in
  99. self.ani1()
  100. }
  101. }
  102. func ani1() {
  103. if chainAni != true {
  104. return
  105. }
  106. UIView.animate(withDuration: 1.5, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: {
  107. self.highlightAction(any: self.handPic)
  108. self.highlightAction(any: self.folderBtn)
  109. }) { (false) in
  110. self.ani2()
  111. }
  112. }
  113. func ani2() {
  114. if chainAni != true {
  115. return
  116. }
  117. UIView.animate(withDuration: 1.5, delay: 1, animations: {
  118. self.unhighlightAction(any: self.handPic)
  119. self.unhighlightAction(any: self.folderBtn)
  120. }) { (false) in
  121. self.ani3()
  122. }
  123. }
  124. func ani3() {
  125. if chainAni != true {
  126. return
  127. }
  128. UIView.animate(withDuration: 0.5, delay: 0, animations: {
  129. self.handPic.alpha = 0
  130. self.alertImg.alpha = 1
  131. self.alertImg.transform = .identity
  132. }) { (false) in
  133. self.ani4()
  134. }
  135. }
  136.  
  137. func clearAni() {
  138. alertImg.image = #imageLiteral(resourceName: "alert1")
  139.  
  140. darkView.removeFromSuperview()
  141. screenView.removeFromSuperview()
  142.  
  143. mainImg.alpha = 1
  144. alertImg.alpha = 0
  145. alert2Img.alpha = 0
  146. handPic.alpha = 0
  147. handPic.transform = .identity
  148. hand2Pic.alpha = 0
  149. hand2Pic.transform = .identity
  150. newFolderImg.alpha = 0
  151. newFolderImg.transform = .identity
  152. }
  153.  
  154. override func viewDidDisappear(_ animated: Bool) {
  155. clearAni()
  156. chainAni = false
  157. }
  158.  
  159. func clearAni() {
  160. alertImg.image = #imageLiteral(resourceName: "alert1")
  161.  
  162. mainImg.layer.removeAllAnimations()
  163. mainLbl.layer.removeAllAnimations()
  164. alertImg.layer.removeAllAnimations()
  165. alert2Img.layer.removeAllAnimations()
  166. folderBtn.layer.removeAllAnimations()
  167. handPic.layer.removeAllAnimations()
  168. hand2Pic.layer.removeAllAnimations()
  169. darkView.layer.removeAllAnimations()
  170.  
  171.  
  172. mainImg.alpha = 1
  173. alertImg.alpha = 0
  174. alert2Img.alpha = 0
  175. handPic.alpha = 0
  176. handPic.transform = .identity
  177. hand2Pic.alpha = 0
  178. hand2Pic.transform = .identity
  179. newFolderImg.alpha = 0
  180. newFolderImg.transform = .identity
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement