Commit 1dc2815d by Daniel Dahan

added comments and reworked SideNavigationViewController to fix issue 102

parent 8d3872d1
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; }; 9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA301C1B906600022BC6 /* BMainViewController.swift */; }; 9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA301C1B906600022BC6 /* BMainViewController.swift */; };
9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* SideViewController.swift */; }; 9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* SideViewController.swift */; };
96668B1C1C29C8F5001916C7 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96668B1B1C29C8F5001916C7 /* MaterialKit.framework */; };
96668B1D1C29C8F5001916C7 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96668B1B1C29C8F5001916C7 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -24,7 +22,6 @@ ...@@ -24,7 +22,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96668B1D1C29C8F5001916C7 /* MaterialKit.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -40,7 +37,6 @@ ...@@ -40,7 +37,6 @@
9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9642FA301C1B906600022BC6 /* BMainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMainViewController.swift; sourceTree = "<group>"; }; 9642FA301C1B906600022BC6 /* BMainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMainViewController.swift; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* SideViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideViewController.swift; sourceTree = "<group>"; }; 9642FA321C1B909700022BC6 /* SideViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideViewController.swift; sourceTree = "<group>"; };
96668B1B1C29C8F5001916C7 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-anypxbsecgdqqxevbavirvnffqxd/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -48,7 +44,6 @@ ...@@ -48,7 +44,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96668B1C1C29C8F5001916C7 /* MaterialKit.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -58,7 +53,6 @@ ...@@ -58,7 +53,6 @@
9642FA0E1C1B50E700022BC6 = { 9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96668B1B1C29C8F5001916C7 /* MaterialKit.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */, 9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */, 9642FA181C1B50E700022BC6 /* Products */,
); );
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
import UIKit import UIKit
import MaterialKit import MaterialKit
class SideViewController: UIViewController { class SideViewController: UIViewController, SideNavigationViewControllerDelegate {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'MK' s.name = 'MK'
s.version = '1.25.8' s.version = '1.26.0'
s.license = { :type => "AGPL-3.0", :file => "LICENSE" } s.license = { :type => "AGPL-3.0", :file => "LICENSE" }
s.summary = 'A beautiful Material Design framework in Swift.' s.summary = 'A beautiful Material Design framework in Swift.'
s.homepage = 'http://materialkit.io' s.homepage = 'http://materialkit.io'
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.25.8</string> <string>1.26.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -20,7 +20,9 @@ import UIKit ...@@ -20,7 +20,9 @@ import UIKit
public extension UIViewController { public extension UIViewController {
/** /**
:name: sideNavigationViewController A convenience property that provides access to the SideNavigationViewController.
This is the recommended method of accessing the SideNavigationViewController
through child UIViewControllers.
*/ */
public var sideNavigationViewController: SideNavigationViewController? { public var sideNavigationViewController: SideNavigationViewController? {
var viewController: UIViewController? = self var viewController: UIViewController? = self
...@@ -34,45 +36,53 @@ public extension UIViewController { ...@@ -34,45 +36,53 @@ public extension UIViewController {
} }
} }
@objc(SideNavigationViewDelegate) @objc(SideNavigationViewControllerDelegate)
public protocol SideNavigationViewDelegate { public protocol SideNavigationViewControllerDelegate {
/** /**
:name: sideNavigationViewWillOpen An optional delegation method that is fired before the
SideNavigationViewController opens.
*/ */
optional func sideNavigationViewWillOpen(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewWillOpen(sideNavigationViewController: SideNavigationViewController)
/** /**
:name: sideNavigationViewDidOpen An optional delegation method that is fired after the
SideNavigationViewController opened.
*/ */
optional func sideNavigationViewDidOpen(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewDidOpen(sideNavigationViewController: SideNavigationViewController)
/** /**
:name: sideNavigationViewWillClose An optional delegation method that is fired before the
SideNavigationViewController closes.
*/ */
optional func sideNavigationViewWillClose(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewWillClose(sideNavigationViewController: SideNavigationViewController)
/** /**
:name: sideNavigationViewDidClose An optional delegation method that is fired after the
SideNavigationViewController closed.
*/ */
optional func sideNavigationViewDidClose(sideNavigationViewController: SideNavigationViewController) optional func sideNavigationViewDidClose(sideNavigationViewController: SideNavigationViewController)
/** /**
:name: sideNavigationViewPanDidBegin An optional delegation method that is fired when the
SideNavigationViewController pan gesture begins.
*/ */
optional func sideNavigationViewPanDidBegin(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidBegin(sideNavigationViewController: SideNavigationViewController, point: CGPoint)
/** /**
:name: sideNavigationViewPanDidChange An optional delegation method that is fired when the
SideNavigationViewController pan gesture changes position.
*/ */
optional func sideNavigationViewPanDidChange(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidChange(sideNavigationViewController: SideNavigationViewController, point: CGPoint)
/** /**
:name: sideNavigationViewPanDidEnd An optional delegation method that is fired when the
SideNavigationViewController pan gesture ends.
*/ */
optional func sideNavigationViewPanDidEnd(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewPanDidEnd(sideNavigationViewController: SideNavigationViewController, point: CGPoint)
/** /**
:name: sideNavigationViewDidTap An optional delegation method that is fired when the
SideNavigationViewController tap gesture begins.
*/ */
optional func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint) optional func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint)
} }
...@@ -80,27 +90,50 @@ public protocol SideNavigationViewDelegate { ...@@ -80,27 +90,50 @@ public protocol SideNavigationViewDelegate {
@objc(SideNavigationViewController) @objc(SideNavigationViewController)
public class SideNavigationViewController: UIViewController, UIGestureRecognizerDelegate { public class SideNavigationViewController: UIViewController, UIGestureRecognizerDelegate {
/** /**
:name: originalPosition A CGPoint property that is used internally to track
the original position of the sideView when panning began.
*/ */
private lazy var originalPosition: CGPoint = CGPointZero private var originalPosition: CGPoint = CGPointZero
/** /**
:name: sidePanGesture A UIPanGestureRecognizer property internally used for the
pan gesture.
*/ */
private var sidePanGesture: UIPanGestureRecognizer? private var sidePanGesture: UIPanGestureRecognizer?
/** /**
:name: sideTapGesture A UITapGestureRecognizer property internally used for the
tap gesture.
*/ */
private var sideTapGesture: UITapGestureRecognizer? private var sideTapGesture: UITapGestureRecognizer?
/** /**
:name: delegate A CAShapeLayer property that is used as the backdrop when
opened. To change the opacity and color of the backdrop,
it is recommended to use the backdropOpcaity property and
backdropColor property, respectively.
*/ */
public weak var delegate: SideNavigationViewDelegate? public private(set) lazy var backdropLayer: CAShapeLayer = CAShapeLayer()
/**
A CGFloat property that accesses the horizontal threshold of
the SideNavigationViewController. When the panning gesture has
ended, if the position is beyond the horizontal threshold,
the sideView is opened, if it is below the threshold, the
sideView is closed. The horizontal threshold is always at half
the width of the sideView.
*/
public private(set) var horizontalThreshold: CGFloat = 0
/** /**
:name: userInteractionEnabled A SideNavigationViewControllerDelegate property used to bind
the delegation object.
*/
public weak var delegate: SideNavigationViewControllerDelegate?
/**
A Boolean property used to enable and disable interactivity
with the mainViewController.
*/ */
public var userInteractionEnabled: Bool { public var userInteractionEnabled: Bool {
get { get {
...@@ -112,69 +145,44 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -112,69 +145,44 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: horizontalThreshold A CGFloat property that sets the animation duration of the
sideView when closing and opening. Defaults to 0.25.
*/ */
public lazy var horizontalThreshold: CGFloat = 0 public var animationDuration: CGFloat = 0.25
/** /**
:name: animationDuration A Boolean property that enables and disables the sideView from
opening and closing. Defaults to true.
*/ */
public lazy var animationDuration: CGFloat = 0.25 public var enabled: Bool = true
/** /**
:name: enabled A Boolean property that triggers the status bar to be hidden
when the sideView is opened. Defaults to true.
*/ */
public lazy var enabled: Bool = true public var hideStatusBar: Bool = true
/** /**
:name: hideStatusBar A MaterialDepth property that is used to set the depth of the
sideView when opened.
*/ */
public lazy var hideStatusBar: Bool = true public var depth: MaterialDepth = .Depth2
/**
:name: depthEnabled
*/
public var depthEnabled: Bool = true {
didSet {
if !depthEnabled {
sideView.depth = .None
}
}
}
/**
:name: depth
*/
public var depth: MaterialDepth = .Depth2 {
didSet {
if !depthEnabled && .None != sideView.depth {
sideView.depth = depth
}
}
}
/** /**
:name: backdropLayer A MaterialView property that is used to hide and reveal the
*/ sideViewController. It is very rare that this property will
public private(set) lazy var backdropLayer: CAShapeLayer = CAShapeLayer() need to be accessed externally.
/**
:name: sideView
*/ */
public private(set) var sideView: MaterialView! public private(set) var sideView: MaterialView!
/** /// A CGFloat property to set the backdropLayer color opacity.
:name: backdropOpacity
*/
public var backdropOpacity: CGFloat = 0.5 { public var backdropOpacity: CGFloat = 0.5 {
didSet { didSet {
backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor
} }
} }
/** /// A UIColor property to set the backdropLayer color.
:name: backdropColor
*/
public var backdropColor: UIColor? { public var backdropColor: UIColor? {
didSet { didSet {
backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor backdropLayer.backgroundColor = backdropColor?.colorWithAlphaComponent(backdropOpacity).CGColor
...@@ -182,55 +190,73 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -182,55 +190,73 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: opened A Boolean property that indicates whether the sideView
is opened.
*/ */
public var opened: Bool { public var opened: Bool {
return sideView.x != -sideViewControllerWidth return sideView.x != -sideViewWidth
} }
/** /**
:name: mainViewController 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! public private(set) var mainViewController: UIViewController!
/** /**
:name: sideViewController A UIViewController property that references the
active side UIViewController.
*/ */
public private(set) var sideViewController: UIViewController! public private(set) var sideViewController: UIViewController!
/** /**
:name: sideViewControllerWidth A CGFloat property to access the width the sideView
opens up to.
*/ */
public private(set) var sideViewControllerWidth: CGFloat = 240 public private(set) var sideViewWidth: CGFloat = 240
/** /**
:name: init An initializer for the SideNavigationViewController.
- Parameter mainViewController: The main UIViewController.
- Parameter sideViewController: The side UIViewController.
*/ */
public convenience init(mainViewController: UIViewController, sideViewController: UIViewController) { public convenience init(mainViewController: UIViewController, sideViewController: UIViewController) {
self.init() self.init()
self.mainViewController = mainViewController self.mainViewController = mainViewController
self.sideViewController = sideViewController self.sideViewController = sideViewController
prepareView() prepareView()
prepareMainViewController()
prepareSideView()
} }
/**
:name: viewWillLayoutSubviews
*/
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
layoutBackdropLayer() MaterialAnimation.animationDisabled { [unowned self] in
horizontalThreshold = sideViewControllerWidth / 2 self.backdropLayer.frame = self.view.bounds
sideView.width = sideViewControllerWidth self.sideView.width = self.sideViewWidth
sideView.height = view.bounds.height self.sideView.height = self.view.bounds.height
}
horizontalThreshold = sideViewWidth / 2
sideViewController.view.frame.size.width = sideView.width sideViewController.view.frame.size.width = sideView.width
sideViewController.view.frame.size.height = sideView.height sideViewController.view.frame.size.height = sideView.height
sideViewController.view.center = CGPointMake(sideView.width / 2, sideView.height / 2) sideViewController.view.center = CGPointMake(sideView.width / 2, sideView.height / 2)
} }
/** /**
:name: transitionFromMainViewController 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, options: UIViewAnimationOptions, animations: (() -> Void)?, completion: ((Bool) -> Void)?) { public func transitionFromMainViewController(toViewController: UIViewController, duration: NSTimeInterval, options: UIViewAnimationOptions, animations: (() -> Void)?, completion: ((Bool) -> Void)?) {
mainViewController.willMoveToParentViewController(nil) mainViewController.willMoveToParentViewController(nil)
...@@ -251,12 +277,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -251,12 +277,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: setSideViewControllerWidth A method that is used to set the width of the sideView when
opened. This is the recommended method of setting the sideView
width.
- Parameter width: A CGFloat value to set as the new width.
- Parameter hidden: A Boolean value of whether the sideView
should be hidden after the width has been updated or not.
- Parameter animated: A Boolean value that indicates to animate
the sideView width change.
*/ */
public func setSideViewControllerWidth(width: CGFloat, hidden: Bool, animated: Bool) { public func setSideViewWidth(width: CGFloat, hidden: Bool, animated: Bool) {
sideViewControllerWidth = width
let w: CGFloat = (hidden ? -width : width) / 2 let w: CGFloat = (hidden ? -width : width) / 2
sideViewWidth = width
if animated { if animated {
MaterialAnimation.animateWithDuration(0.25, animations: { [unowned self] in MaterialAnimation.animateWithDuration(0.25, animations: { [unowned self] in
...@@ -274,14 +306,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -274,14 +306,21 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: toggle A method that toggles the sideView opened if previously closed,
or closed if previously opened.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
sideView. Defaults to 0.
*/ */
public func toggle(velocity: CGFloat = 0) { public func toggle(velocity: CGFloat = 0) {
opened ? close(velocity) : open(velocity) opened ? close(velocity) : open(velocity)
} }
/** /**
:name: open A method that opens the sideView.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
sideView. Defaults to 0.
*/ */
public func open(velocity: CGFloat = 0) { public func open(velocity: CGFloat = 0) {
toggleStatusBar(true) toggleStatusBar(true)
...@@ -294,19 +333,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -294,19 +333,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self.sideView.position = CGPointMake(self.sideView.width / 2, self.sideView.height / 2) self.sideView.position = CGPointMake(self.sideView.width / 2, self.sideView.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showSideViewDepth()
if self.depthEnabled {
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.depth = self.depth
}
}
self.delegate?.sideNavigationViewDidOpen?(self) self.delegate?.sideNavigationViewDidOpen?(self)
} }
} }
/** /**
:name: close A method that closes the sideView.
- Parameter velocity: A CGFloat value that sets the
velocity of the user interaction when animating the
sideView. Defaults to 0.
*/ */
public func close(velocity: CGFloat = 0) { public func close(velocity: CGFloat = 0) {
toggleStatusBar(false) toggleStatusBar(false)
...@@ -319,24 +355,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -319,24 +355,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
self.sideView.position = CGPointMake(-self.sideView.width / 2, self.sideView.height / 2) self.sideView.position = CGPointMake(-self.sideView.width / 2, self.sideView.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = true self.userInteractionEnabled = true
self.hideSideViewDepth()
if self.depthEnabled {
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.depth = .None
}
}
self.delegate?.sideNavigationViewDidClose?(self) self.delegate?.sideNavigationViewDidClose?(self)
} }
} }
/**
:name: gestureRecognizer
*/
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool { public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if enabled { if enabled {
if gestureRecognizer == sidePanGesture { if gestureRecognizer == sidePanGesture {
return gesturePanSideViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view)) return opened || enabled && isPointContainedWithinRect(touch.locationInView(view))
} }
if opened && gestureRecognizer == sideTapGesture { if opened && gestureRecognizer == sideTapGesture {
let point: CGPoint = touch.locationInView(view) let point: CGPoint = touch.locationInView(view)
...@@ -348,48 +375,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -348,48 +375,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: prepareView A method that is fired when the pan gesture is recognized
*/ for the SideNavigationViewController.
public func prepareView() { - Parameter recognizer: A UIPanGestureRecognizer that is
prepareBackdropLayer() passed to the handler when recognized.
}
/**
:name: prepareMainViewController
*/
internal func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
mainViewController.view.frame = view.bounds
}
/**
:name: prepareSideViewController
*/
internal func prepareSideViewController() {
sideViewController.view.clipsToBounds = true
prepareViewControllerWithinContainer(sideViewController, container: sideView)
}
/**
:name: prepareSideView
*/
internal func prepareSideView() {
sideView = MaterialView()
sideView.frame = CGRectMake(0, 0, sideViewControllerWidth, view.frame.height)
sideView.backgroundColor = MaterialColor.clear
view.addSubview(sideView)
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.position.x = -self.sideViewControllerWidth / 2
self.sideView.zPosition = 1000
}
prepareSideViewController()
prepareGestures()
}
/**
:name: handlePanGesture
*/ */
internal func handlePanGesture(recognizer: UIPanGestureRecognizer) { internal func handlePanGesture(recognizer: UIPanGestureRecognizer) {
switch recognizer.state { switch recognizer.state {
...@@ -397,11 +386,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -397,11 +386,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = false backdropLayer.hidden = false
originalPosition = sideView.position originalPosition = sideView.position
toggleStatusBar(true) toggleStatusBar(true)
if depthEnabled { showSideViewDepth()
MaterialAnimation.animationDisabled { [unowned self, sideView = self.sideView] in
sideView.depth = self.depth
}
}
delegate?.sideNavigationViewPanDidBegin?(self, point: sideView.position) delegate?.sideNavigationViewPanDidBegin?(self, point: sideView.position)
case .Changed: case .Changed:
let translation: CGPoint = recognizer.translationInView(sideView) let translation: CGPoint = recognizer.translationInView(sideView)
...@@ -417,7 +402,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -417,7 +402,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate?.sideNavigationViewPanDidEnd?(self, point: sideView.position) delegate?.sideNavigationViewPanDidEnd?(self, point: sideView.position)
if sideView.x <= CGFloat(floor(-sideViewControllerWidth)) + horizontalThreshold || point.x <= -1000 { if sideView.x <= CGFloat(floor(-sideViewWidth)) + horizontalThreshold || point.x <= -1000 {
close(x) close(x)
} else { } else {
open(x) open(x)
...@@ -427,16 +412,96 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -427,16 +412,96 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: handleTapGesture A method that is fired when the tap gesture is recognized
for the SideNavigationViewController.
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
*/ */
internal func handleTapGesture(recognizer: UIPanGestureRecognizer) { internal func handleTapGesture(recognizer: UITapGestureRecognizer) {
if opened { if opened {
close() close()
} }
} }
/** /**
:name: prepareGestures A method that generally prepares the SideNavigationViewController.
*/
private func prepareView() {
prepareBackdropLayer()
prepareMainViewController()
prepareSideView()
}
/**
A method that prepares the mainViewController.
*/
private func prepareMainViewController() {
prepareViewControllerWithinContainer(mainViewController, container: view)
mainViewController.view.frame = view.bounds
}
/**
A method that prepares the sideViewController.
*/
private func prepareSideViewController() {
sideViewController.view.clipsToBounds = true
prepareViewControllerWithinContainer(sideViewController, container: sideView)
}
/**
A method that prepares the sideView.
*/
private func prepareSideView() {
sideView = MaterialView()
sideView.frame = CGRectMake(0, 0, sideViewWidth, view.frame.height)
sideView.backgroundColor = MaterialColor.clear
view.addSubview(sideView)
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.position.x = -self.sideViewWidth / 2
self.sideView.zPosition = 1000
}
prepareSideViewController()
removeGestures(&sidePanGesture, tap: &sideTapGesture)
prepareGestures(&sidePanGesture, panSelector: "handlePanGesture:", tap: &sideTapGesture, tapSelector: "handleTapGesture:")
}
/**
A method that prepares the backdropLayer.
*/
private func prepareBackdropLayer() {
backdropColor = MaterialColor.black
backdropLayer.zPosition = 900
backdropLayer.hidden = true
view.layer.addSublayer(backdropLayer)
}
/**
A method that adds the passed in controller as a child of
the SideNavigationViewController within the passed in
container view.
- Parameter controller: 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(controller: UIViewController, container: UIView) {
addChildViewController(controller)
container.addSubview(controller.view)
controller.didMoveToParentViewController(self)
}
/**
A method that prepares the gestures used within the
SideNavigationViewController.
- Parameter pan: A UIPanGestureRecognizer that is used to
recognize pan gestures.
- Parameter panSelector: A Selector that is fired when the
pan gesture is recognized.
- Parameter tap: A UITapGestureRecognizer that is used to
recognize tap gestures.
- Parameter tapSelector: A Selector that is fired when the
tap gesture is recognized.
*/ */
private func prepareGestures(inout pan: UIPanGestureRecognizer?, panSelector: Selector, inout tap: UITapGestureRecognizer?, tapSelector: Selector) { private func prepareGestures(inout pan: UIPanGestureRecognizer?, panSelector: Selector, inout tap: UITapGestureRecognizer?, tapSelector: Selector) {
if nil == pan { if nil == pan {
...@@ -452,7 +517,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -452,7 +517,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: removeGestures A method that removes the passed in pan and tap gesture
recognizers.
- Parameter pan: A UIPanGestureRecognizer that should be
removed from the SideNavigationViewController.
- Parameter tap: A UITapGestureRecognizer that should be
removed from the SideNavigationViewController.
*/ */
private func removeGestures(inout pan: UIPanGestureRecognizer?, inout tap: UITapGestureRecognizer?) { private func removeGestures(inout pan: UIPanGestureRecognizer?, inout tap: UITapGestureRecognizer?) {
if let v: UIPanGestureRecognizer = pan { if let v: UIPanGestureRecognizer = pan {
...@@ -466,7 +536,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -466,7 +536,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: toggleStatusBar A method to toggle the status bar from a reveal state to
hidden state. The hideStatusBar property needs to be set
to true in order for this method to have any affect.
- Parameter hide: A Boolean indicating to show or hide
the status bar.
*/ */
private func toggleStatusBar(hide: Bool = false) { private func toggleStatusBar(hide: Bool = false) {
if hideStatusBar { if hideStatusBar {
...@@ -475,68 +549,48 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -475,68 +549,48 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
:name: removeViewController A method that determines whether the passed point is
contained within the bounds of the horizontalThreshold
and height of the SideNavigationViewController view frame
property.
- Parameter point: A CGPoint to test against.
- Returns: A Boolean of the result, true if yes, false
otherwise.
*/ */
private func removeViewController(controller: UIViewController) { private func isPointContainedWithinRect(point: CGPoint) -> Bool {
controller.willMoveToParentViewController(nil)
controller.view.removeFromSuperview()
controller.removeFromParentViewController()
}
/**
:name: gesturePanSideViewController
*/
private func gesturePanSideViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return opened || enabled && isLeftPointContainedWithinRect(point)
}
/**
:name: isLeftPointContainedWithinRect
*/
private func isLeftPointContainedWithinRect(point: CGPoint) -> Bool {
return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.frame.height), point) return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.frame.height), point)
} }
/** /**
:name: isPointContainedWithinViewController A method that determines whether the passed in point is
contained within the bounds of the passed in container view.
- Parameter container: A UIView that sets the bounds to test
against.
- Parameter point: A CGPoint to test whether or not it is
within the bounds of the container parameter.
- Returns: A Boolean of the result, true if yes, false
otherwise.
*/ */
private func isPointContainedWithinViewController(container: UIView, point: CGPoint) -> Bool { private func isPointContainedWithinViewController(container: UIView, point: CGPoint) -> Bool {
return CGRectContainsPoint(container.frame, point) return CGRectContainsPoint(container.frame, point)
} }
/** /**
:name: prepareBackdropLayer A method that adds the depth to the sideView depth property.
*/ */
private func prepareBackdropLayer() { private func showSideViewDepth() {
backdropColor = MaterialColor.black
backdropLayer.zPosition = 900
backdropLayer.hidden = true
view.layer.addSublayer(backdropLayer)
}
/**
:name: layoutBackdropLayer
*/
private func layoutBackdropLayer() {
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
self.backdropLayer.frame = self.view.bounds self.sideView.depth = self.depth
} }
} }
/** /**
:name: prepareViewControllerWithinContainer A method that removes the depth from the sideView depth
property.
*/ */
private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) { private func hideSideViewDepth() {
addChildViewController(controller) MaterialAnimation.animationDisabled { [unowned self] in
container.addSubview(controller.view) self.sideView.depth = .None
controller.didMoveToParentViewController(self)
} }
/**
:name: prepareGestures
*/
private func prepareGestures() {
removeGestures(&sidePanGesture, tap: &sideTapGesture)
prepareGestures(&sidePanGesture, panSelector: "handlePanGesture:", tap: &sideTapGesture, tapSelector: "handleTapGesture:")
} }
} }
\ No newline at end of file
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