Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Charles SORIN committed Sep 4, 2017
2 parents 8591d06 + 6046cf5 commit 537aba4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Example/Extra/ViewControllers/UIKit/UIKitExamples.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="tQT-L0-7Xy">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="tQT-L0-7Xy">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -25,7 +25,7 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="AxB-zb-Gbs">
<rect key="frame" x="67" y="99.5" width="240" height="120"/>
<color key="backgroundColor" red="1" green="0.14954377690000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="3NX-fX-Vne"/>
<constraint firstAttribute="height" constant="120" id="eU4-Np-6yb"/>
Expand Down
19 changes: 14 additions & 5 deletions Example/Extra/ViewControllers/UIKit/UIKitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ 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)
self.ex.switchChilds(from: nil, to: newVc, in: self.ibExampleView, duration: 1)
}

}
Expand Down Expand Up @@ -78,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
}
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Extra: 8de8602637173951173cdd667609f68eaaa21716
Extra: 3130a9f2b593fd190167da7355b25f682536dc96
Realm: 98b3a25643cf6b3e07d2b99fb43fe0eb9c801dec
RealmSwift: 34073ad3a31232bbaf7c0db898c037940284cba2
RxCocoa: a8a5f1d061d0043e28f56976829f31ce63e8eb09
Expand Down
26 changes: 19 additions & 7 deletions Extra/Classes/UIKit/UIViewController+Extra.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -90,9 +101,13 @@ extension Extra where Base: UIViewController {
in viewContainer: UIView,
duration: TimeInterval = 0.3,
transitionOptions: UIViewAnimationOptions = .transitionCrossDissolve,
insets: UIEdgeInsets = .zero,
completion: ((Bool) -> Void)? = nil) {

destinationController.view.bounds = viewContainer.bounds
guard destinationController != originController else {
return
}
destinationController.view.frame = viewContainer.bounds

if let originController = originController {
originController.willMove(toParentViewController: nil)
Expand All @@ -103,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)
})
}
Expand Down

0 comments on commit 537aba4

Please sign in to comment.