Commit 59fc39a9 by Daniel Dahan

refactored SearchBarViewController and NavigationBarViewController to use a…

refactored SearchBarViewController and NavigationBarViewController to use a common StatusBarViewController
parent ad2ec779
Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. All rights reserved. Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of Material nor the names of its * Neither the name of Material nor the names of its
contributors may be used to endorse or promote products derived from contributors may be used to endorse or promote products derived from
this software without specific prior written permission. this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
96CC08361C7CCB7C0034FF84 /* SearchBarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96CC08361C7CCB7C0034FF84 /* SearchBarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC08371C7CCB7C0034FF84 /* SearchBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 960036141C77E1B600EBA579 /* SearchBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96CC08371C7CCB7C0034FF84 /* SearchBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 960036141C77E1B600EBA579 /* SearchBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96CC083D1C7CF9D40034FF84 /* StatusBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; };
96CC083E1C7CFF2A0034FF84 /* StatusBarViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; }; 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
...@@ -161,6 +163,7 @@ ...@@ -161,6 +163,7 @@
96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; }; 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; }; 96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; };
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; }; 96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarViewController.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; }; 96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; }; 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
...@@ -480,6 +483,7 @@ ...@@ -480,6 +483,7 @@
children = ( children = (
96A71FB01C7649F800C0C4AE /* ControlView.swift */, 96A71FB01C7649F800C0C4AE /* ControlView.swift */,
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */, 96A71FB21C764E3200C0C4AE /* StatusBarView.swift */,
96CC083C1C7CF9D40034FF84 /* StatusBarViewController.swift */,
); );
name = StatusBar; name = StatusBar;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -554,6 +558,7 @@ ...@@ -554,6 +558,7 @@
96CC08361C7CCB7C0034FF84 /* SearchBarView.swift in Headers */, 96CC08361C7CCB7C0034FF84 /* SearchBarView.swift in Headers */,
96CC08371C7CCB7C0034FF84 /* SearchBarViewController.swift in Headers */, 96CC08371C7CCB7C0034FF84 /* SearchBarViewController.swift in Headers */,
96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */, 96CC08381C7CCB7C0034FF84 /* NavigationBarViewController.swift in Headers */,
96CC083E1C7CFF2A0034FF84 /* StatusBarViewController.swift in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -704,6 +709,7 @@ ...@@ -704,6 +709,7 @@
96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */, 96D88C211C1328D800B91418 /* CaptureSession.swift in Sources */,
96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */, 96442ADE1C28EF3700C3C574 /* MaterialTableViewCell.swift in Sources */,
960B23271C383E5500E96216 /* Material+String.swift in Sources */, 960B23271C383E5500E96216 /* Material+String.swift in Sources */,
96CC083D1C7CF9D40034FF84 /* StatusBarViewController.swift in Sources */,
960B23471C38480E00E96216 /* TextStorage.swift in Sources */, 960B23471C38480E00E96216 /* TextStorage.swift in Sources */,
96D88C341C1328D800B91418 /* MaterialLayer.swift in Sources */, 96D88C341C1328D800B91418 /* MaterialLayer.swift in Sources */,
96D88C461C1328D800B91418 /* SideNavigationViewController.swift in Sources */, 96D88C461C1328D800B91418 /* SideNavigationViewController.swift in Sources */,
......
...@@ -48,7 +48,7 @@ public extension UIViewController { ...@@ -48,7 +48,7 @@ public extension UIViewController {
} }
} }
public class NavigationBarViewController: UIViewController { public class NavigationBarViewController: StatusBarViewController {
/// Internal reference to the floatingViewController. /// Internal reference to the floatingViewController.
private var internalFloatingViewController: UIViewController? private var internalFloatingViewController: UIViewController?
...@@ -102,80 +102,21 @@ public class NavigationBarViewController: UIViewController { ...@@ -102,80 +102,21 @@ public class NavigationBarViewController: UIViewController {
} }
} }
/**
A Boolean property used to enable and disable interactivity
with the mainViewController.
*/
public var userInteractionEnabled: Bool {
get {
return mainViewController.view.userInteractionEnabled
}
set(value) {
mainViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it
is recommended to use the transitionFromMainViewController
helper method.
*/
public private(set) var mainViewController: UIViewController!
/**
An initializer for the NavigationBarViewController.
- Parameter mainViewController: The main UIViewController.
*/
public convenience init(mainViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
prepareView()
}
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
layoutSubviews() layoutSubviews()
} }
/** /**
A method to swap mainViewController objects. Prepares the view instance when intialized. When subclassing,
- Parameter toViewController: The UIViewController to swap it is recommended to override the prepareView method
with the active mainViewController. to initialize property values and other setup operations.
- Parameter duration: A NSTimeInterval that sets the The super.prepareView method should always be called at the end
animation duration of the transition. when subclassing.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active mainViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController
to the toViewController has completed.
*/ */
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { public override func prepareView() {
mainViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController)
toViewController.view.frame = mainViewController.view.frame
transitionFromViewController(mainViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController()
self.mainViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view)
completion?(result)
})
}
/// A method that generally prepares the NavigationBarViewController.
private func prepareView() {
prepareNavigationBarView() prepareNavigationBarView()
prepareMainViewController() super.prepareView()
} }
/// Prepares the NavigationBarView. /// Prepares the NavigationBarView.
...@@ -185,27 +126,6 @@ public class NavigationBarViewController: UIViewController { ...@@ -185,27 +126,6 @@ public class NavigationBarViewController: UIViewController {
view.addSubview(navigationBarView) view.addSubview(navigationBarView)
} }
/// A method that prepares the mainViewController.
private func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
}
/**
A method that adds the passed in controller as a child of
the NavigationBarViewController within the passed in
container view.
- Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
container.insertSubview(v.view, atIndex: 0)
v.didMoveToParentViewController(self)
}
}
/// Layout subviews. /// Layout subviews.
private func layoutSubviews() { private func layoutSubviews() {
let size: CGSize = UIScreen.mainScreen().bounds.size let size: CGSize = UIScreen.mainScreen().bounds.size
......
...@@ -48,84 +48,25 @@ public extension UIViewController { ...@@ -48,84 +48,25 @@ public extension UIViewController {
} }
} }
public class SearchBarViewController: UIViewController { public class SearchBarViewController: StatusBarViewController {
/// Reference to the SearchBarView. /// Reference to the SearchBarView.
public private(set) lazy var searchBarView: SearchBarView = SearchBarView() public private(set) lazy var searchBarView: SearchBarView = SearchBarView()
/**
A Boolean property used to enable and disable interactivity
with the mainViewController.
*/
public var userInteractionEnabled: Bool {
get {
return mainViewController.view.userInteractionEnabled
}
set(value) {
mainViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it
is recommended to use the transitionFromMainViewController
helper method.
*/
public private(set) var mainViewController: UIViewController!
/**
An initializer for the SearchBarViewController.
- Parameter mainViewController: The main UIViewController.
*/
public convenience init(mainViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
prepareView()
}
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
layoutSubviews() layoutSubviews()
} }
/** /**
A method to swap mainViewController objects. Prepares the view instance when intialized. When subclassing,
- Parameter toViewController: The UIViewController to swap it is recommended to override the prepareView method
with the active mainViewController. to initialize property values and other setup operations.
- Parameter duration: A NSTimeInterval that sets the The super.prepareView method should always be called at the end
animation duration of the transition. when subclassing.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active mainViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController
to the toViewController has completed.
*/ */
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) { public override func prepareView() {
mainViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController)
toViewController.view.frame = mainViewController.view.frame
transitionFromViewController(mainViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController()
self.mainViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view)
completion?(result)
})
}
/// A method that generally prepares the SearchBarViewController.
private func prepareView() {
prepareSearchBarView() prepareSearchBarView()
prepareMainViewController() super.prepareView()
} }
/// Prepares the SearchBarView. /// Prepares the SearchBarView.
...@@ -135,27 +76,6 @@ public class SearchBarViewController: UIViewController { ...@@ -135,27 +76,6 @@ public class SearchBarViewController: UIViewController {
view.addSubview(searchBarView) view.addSubview(searchBarView)
} }
/// A method that prepares the mainViewController.
private func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
}
/**
A method that adds the passed in controller as a child of
the SearchBarViewController within the passed in
container view.
- Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
container.insertSubview(v.view, atIndex: 0)
v.didMoveToParentViewController(self)
}
}
/// Layout subviews. /// Layout subviews.
private func layoutSubviews() { private func layoutSubviews() {
let size: CGSize = UIScreen.mainScreen().bounds.size let size: CGSize = UIScreen.mainScreen().bounds.size
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public class StatusBarViewController: UIViewController {
/**
A Boolean property used to enable and disable interactivity
with the mainViewController.
*/
public var userInteractionEnabled: Bool {
get {
return mainViewController.view.userInteractionEnabled
}
set(value) {
mainViewController.view.userInteractionEnabled = value
}
}
/**
A UIViewController property that references the active
main UIViewController. To swap the mainViewController, it
is recommended to use the transitionFromMainViewController
helper method.
*/
public private(set) var mainViewController: UIViewController!
/**
An initializer for the StatusBarViewController.
- Parameter mainViewController: The main UIViewController.
*/
public convenience init(mainViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
prepareView()
}
/**
A method to swap mainViewController objects.
- Parameter toViewController: The UIViewController to swap
with the active mainViewController.
- Parameter duration: A NSTimeInterval that sets the
animation duration of the transition.
- Parameter options: UIViewAnimationOptions thst are used
when animating the transition from the active mainViewController
to the toViewController.
- Parameter animations: An animation block that is executed during
the transition from the active mainViewController
to the toViewController.
- Parameter completion: A completion block that is execited after
the transition animation from the active mainViewController
to the toViewController has completed.
*/
public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval = 0.5, options: UIViewAnimationOptions = [], animations: (() -> Void)? = nil, completion: ((Bool) -> Void)? = nil) {
mainViewController.willMoveToParentViewController(nil)
addChildViewController(toViewController)
toViewController.view.frame = mainViewController.view.frame
transitionFromViewController(mainViewController,
toViewController: toViewController,
duration: duration,
options: options,
animations: animations,
completion: { [unowned self] (result: Bool) in
toViewController.didMoveToParentViewController(self)
self.mainViewController.removeFromParentViewController()
self.mainViewController = toViewController
self.view.sendSubviewToBack(self.mainViewController.view)
completion?(result)
})
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called at the end
when subclassing.
*/
public func prepareView() {
prepareMainViewController()
}
/// A method that prepares the mainViewController.
private func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
}
/**
A method that adds the passed in controller as a child of
the StatusBarViewController within the passed in
container view.
- Parameter viewController: A UIViewController to add as a child.
- Parameter container: A UIView that is the parent of the
passed in controller view within the view hierarchy.
*/
private func prepareViewControllerWithinContainer(viewController: UIViewController?, container: UIView) {
if let v: UIViewController = viewController {
addChildViewController(v)
container.insertSubview(v.view, atIndex: 0)
v.didMoveToParentViewController(self)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment