From df6c3ebdd958b5fe95c1789e1c7d6aaa41bb27da Mon Sep 17 00:00:00 2001 From: Martin Barreto Date: Mon, 23 Jan 2017 17:54:30 -0300 Subject: [PATCH] fix #172 & #189 --- .../Example/Base.lproj/Storyboard.storyboard | 209 +++++++++--------- Sources/PagerTabStripViewController.swift | 30 ++- 2 files changed, 133 insertions(+), 106 deletions(-) diff --git a/Example/Example/Base.lproj/Storyboard.storyboard b/Example/Example/Base.lproj/Storyboard.storyboard index ece405a..be82bd4 100644 --- a/Example/Example/Base.lproj/Storyboard.storyboard +++ b/Example/Example/Base.lproj/Storyboard.storyboard @@ -1,10 +1,14 @@ - - + + + + + - + + @@ -16,15 +20,15 @@ - + - - + + - + @@ -36,16 +40,16 @@ - + - + - + @@ -69,43 +73,42 @@ - + - - + + - + @@ -154,17 +157,17 @@ - + - + - + @@ -174,7 +177,7 @@ - + @@ -194,22 +197,22 @@ - + - - + + - - + + - + @@ -235,24 +238,24 @@ - + - + - + - + @@ -266,17 +269,17 @@ - + - + @@ -286,17 +289,17 @@ - + - + @@ -306,17 +309,17 @@ - + - + @@ -348,7 +351,7 @@ - + @@ -371,11 +374,11 @@ - + - + @@ -388,11 +391,11 @@ - + - + @@ -438,7 +441,7 @@ - + @@ -460,10 +463,10 @@ - + - + @@ -484,15 +487,15 @@ - + - + - - + + @@ -505,7 +508,7 @@ - + @@ -535,15 +538,15 @@ - + - - + + - + @@ -555,7 +558,7 @@ - + @@ -580,7 +583,7 @@ - + @@ -602,10 +605,10 @@ - + - + @@ -626,15 +629,15 @@ - + - - + + - + @@ -664,10 +667,10 @@ - + - - + + @@ -693,12 +696,12 @@ - - + + - - + + @@ -723,16 +726,16 @@ - + - - + + - + @@ -757,7 +760,7 @@ - + @@ -791,12 +794,12 @@ - - + + - - + + @@ -821,16 +824,16 @@ - + - - + + - + @@ -855,7 +858,7 @@ - + @@ -873,10 +876,10 @@ - + - + diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index 5b245e6..bcb60bb 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -105,11 +105,18 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { containerView.showsHorizontalScrollIndicator = false containerView.isPagingEnabled = true reloadViewControllers() + + let childController = viewControllers[currentIndex] + addChildViewController(childController) + childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] + containerView.addSubview(childController.view) + childController.didMove(toParentViewController: self) } open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) isViewAppearing = true + childViewControllers.forEach { $0.beginAppearanceTransition(true, animated: animated) } } override open func viewDidAppear(_ animated: Bool) { @@ -117,6 +124,17 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { lastSize = containerView.bounds.size updateIfNeeded() isViewAppearing = false + childViewControllers.forEach { $0.endAppearanceTransition() } + } + + open override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + childViewControllers.forEach { $0.beginAppearanceTransition(false, animated: animated) } + } + + open override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + childViewControllers.forEach { $0.endAppearanceTransition() } } override open func viewDidLayoutSubviews(){ @@ -124,6 +142,10 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { updateIfNeeded() } + open override var shouldAutomaticallyForwardAppearanceMethods: Bool { + return false + } + open func moveToViewController(at index: Int, animated: Bool = true) { guard isViewLoaded && view.window != nil && currentIndex != index else { currentIndex = index @@ -222,8 +244,8 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] } else { - addChildViewController(childController) childController.beginAppearanceTransition(true, animated: false) + addChildViewController(childController) childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height) childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] containerView.addSubview(childController.view) @@ -233,8 +255,8 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { } else { if let _ = childController.parent { - childController.willMove(toParentViewController: nil) childController.beginAppearanceTransition(false, animated: false) + childController.willMove(toParentViewController: nil) childController.view.removeFromSuperview() childController.removeFromParentViewController() childController.endAppearanceTransition() @@ -262,9 +284,11 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { guard isViewLoaded else { return } for childController in viewControllers { if let _ = childController.parent { - childController.view.removeFromSuperview() + childController.beginAppearanceTransition(false, animated: false) childController.willMove(toParentViewController: nil) + childController.view.removeFromSuperview() childController.removeFromParentViewController() + childController.endAppearanceTransition() } } reloadViewControllers()