From a7998134764467b3a045d9cc1bd4dba841deb191 Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Tue, 22 Aug 2017 20:36:43 +0200 Subject: [PATCH 1/4] Fix podspec --- Extra.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Extra.podspec b/Extra.podspec index 8119e94..6183d1b 100644 --- a/Extra.podspec +++ b/Extra.podspec @@ -16,11 +16,11 @@ Pod::Spec.new do |s| s.default_subspec = 'UIKit', 'Foundation' s.subspec 'UIKit' do |sp| - sp.source_files = 'Extra/Classes/UIKit/**/*.{swift}' + sp.source_files = 'Extra/Classes/Extra/**/*.{swift}', 'Extra/Classes/UIKit/**/*.{swift}' end s.subspec 'Foundation' do |sp| - sp.source_files = 'Extra/Classes/Foundation/**/*.{swift}' + sp.source_files = 'Extra/Classes/Extra/**/*.{swift}', 'Extra/Classes/Foundation/**/*.{swift}' end s.subspec 'Realm' do |sp| From 5334c47062b38c7f2a56638fe3cffa439c44831b Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Mon, 28 Aug 2017 16:08:48 +0200 Subject: [PATCH 2/4] Fix addChild frame to bounds of container and add removeChild method --- .../UIKit/UIKitExamples.storyboard | 4 ++-- .../UIKit/UIKitViewController.swift | 4 ++++ Example/Podfile.lock | 2 +- Extra/Classes/UIKit/UIViewController+Extra.swift | 15 +++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Example/Extra/ViewControllers/UIKit/UIKitExamples.storyboard b/Example/Extra/ViewControllers/UIKit/UIKitExamples.storyboard index a3eaf6c..d28172f 100644 --- a/Example/Extra/ViewControllers/UIKit/UIKitExamples.storyboard +++ b/Example/Extra/ViewControllers/UIKit/UIKitExamples.storyboard @@ -1,5 +1,5 @@ - + @@ -25,7 +25,7 @@ - + diff --git a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift index 8cddeab..128f88f 100644 --- a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift +++ b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift @@ -48,6 +48,10 @@ final class UIKitViewController: UIViewController { self.ibTableView.delegate = self let nib = UINib(nibName: LabelCell.reuseIdentifier, bundle: nil) self.ibTableView.register(nib, forCellReuseIdentifier: LabelCell.reuseIdentifier) + + let newVc = ColorViewController() + newVc.color = self.childViewControllers.last?.view.backgroundColor == .orange ? .blue : .orange + self.ex.addChildViewController(newVc, in: self.ibExampleView, insets: .zero) } } diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 811b3ab..7d78fb5 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -29,7 +29,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - Extra: 8de8602637173951173cdd667609f68eaaa21716 + Extra: 3130a9f2b593fd190167da7355b25f682536dc96 Realm: 98b3a25643cf6b3e07d2b99fb43fe0eb9c801dec RealmSwift: 34073ad3a31232bbaf7c0db898c037940284cba2 RxCocoa: a8a5f1d061d0043e28f56976829f31ce63e8eb09 diff --git a/Extra/Classes/UIKit/UIViewController+Extra.swift b/Extra/Classes/UIKit/UIViewController+Extra.swift index dee8d76..f3eee25 100644 --- a/Extra/Classes/UIKit/UIViewController+Extra.swift +++ b/Extra/Classes/UIKit/UIViewController+Extra.swift @@ -69,11 +69,22 @@ extension Extra where Base: UIViewController { if let childView = childController.view { self.base.addChildViewController(childController) + childView.frame = container.bounds container.ex.addSubview(childView, insets: insets) + childController.didMove(toParentViewController: self.base) + } else { fatalError("Your view controller \(childController) does not contain any view") } - + } + + /// Remove the desired childViewController properly from its parent + /// + /// - Parameter childViewController: child controller to remove + public func removeChildViewController(_ childViewController: UIViewController) { + childViewController.willMove(toParentViewController: nil) + childViewController.view.removeFromSuperview() + childViewController.removeFromParentViewController() } /// Switch between child view controllers @@ -92,7 +103,7 @@ extension Extra where Base: UIViewController { transitionOptions: UIViewAnimationOptions = .transitionCrossDissolve, completion: ((Bool) -> Void)? = nil) { - destinationController.view.bounds = viewContainer.bounds + destinationController.view.frame = viewContainer.bounds if let originController = originController { originController.willMove(toParentViewController: nil) From 287653e272b176432e032dfd8ae2e50d171376e4 Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Tue, 29 Aug 2017 23:35:04 +0200 Subject: [PATCH 3/4] Improve switching and unbalanced warnings --- .../ViewControllers/UIKit/UIKitViewController.swift | 3 ++- Extra/Classes/UIKit/UIViewController+Extra.swift | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift index 128f88f..c411ae8 100644 --- a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift +++ b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift @@ -51,7 +51,8 @@ final class UIKitViewController: UIViewController { let newVc = ColorViewController() newVc.color = self.childViewControllers.last?.view.backgroundColor == .orange ? .blue : .orange - self.ex.addChildViewController(newVc, in: self.ibExampleView, insets: .zero) + //self.ex.addChildViewController(newVc, in: self.ibExampleView, insets: .zero) + self.ex.switchChilds(from: nil, to: newVc, in: self.ibExampleView, duration: 3) } } diff --git a/Extra/Classes/UIKit/UIViewController+Extra.swift b/Extra/Classes/UIKit/UIViewController+Extra.swift index f3eee25..db4b3e8 100644 --- a/Extra/Classes/UIKit/UIViewController+Extra.swift +++ b/Extra/Classes/UIKit/UIViewController+Extra.swift @@ -101,8 +101,12 @@ extension Extra where Base: UIViewController { in viewContainer: UIView, duration: TimeInterval = 0.3, transitionOptions: UIViewAnimationOptions = .transitionCrossDissolve, + insets: UIEdgeInsets = .zero, completion: ((Bool) -> Void)? = nil) { + guard destinationController != originController else { + return + } destinationController.view.frame = viewContainer.bounds if let originController = originController { @@ -114,21 +118,18 @@ extension Extra where Base: UIViewController { options: transitionOptions, animations: nil, completion: { completed in - viewContainer.ex.setSubviewConstraints(destinationController.view) originController.removeFromParentViewController() destinationController.didMove(toParentViewController: self.base) completion?(completed) }) } else { - self.base.addChildViewController(destinationController) - viewContainer.ex.addSubview(destinationController.view, insets: .zero) - destinationController.view.alpha = 0 + self.addChildViewController(destinationController, in: viewContainer, insets: insets) + UIView.animate(withDuration: duration, animations: { destinationController.view.alpha = 1 }, completion: { finished in - destinationController.didMove(toParentViewController: self.base) completion?(finished) }) } From 22ab15fa952a33caa5c58936a32d70f9c5939fcd Mon Sep 17 00:00:00 2001 From: Jean-Charles SORIN Date: Wed, 30 Aug 2017 11:01:16 +0200 Subject: [PATCH 4/4] Update example --- .../UIKit/UIKitViewController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift index c411ae8..4dc0cd0 100644 --- a/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift +++ b/Example/Extra/ViewControllers/UIKit/UIKitViewController.swift @@ -52,7 +52,7 @@ final class UIKitViewController: UIViewController { let newVc = ColorViewController() newVc.color = self.childViewControllers.last?.view.backgroundColor == .orange ? .blue : .orange //self.ex.addChildViewController(newVc, in: self.ibExampleView, insets: .zero) - self.ex.switchChilds(from: nil, to: newVc, in: self.ibExampleView, duration: 3) + self.ex.switchChilds(from: nil, to: newVc, in: self.ibExampleView, duration: 1) } } @@ -83,11 +83,15 @@ extension UIKitViewController: UITableViewDelegate { let currentVc = self.childViewControllers.last let newVc = ColorViewController() newVc.color = currentVc?.view.backgroundColor == .orange ? .blue : .orange - self.ex.switchChilds(from: currentVc, to: newVc, in: self.ibExampleView) - self.ex.switchChilds(from: currentVc, to: newVc, in: self.ibExampleView, duration: 3, completion: { (finished) in - if finished { - self.switchLocked = false - } + self.ex.switchChilds(from: currentVc, + to: newVc, + in: self.ibExampleView, + duration: 1, + transitionOptions: .transitionFlipFromLeft, + completion: { (finished) in + if finished { + self.switchLocked = false + } }) } }