Commit c73bd151 by Daniel Dahan

updated SideNavigationController internals to better handle panning and to…

updated SideNavigationController internals to better handle panning and to remove gestures when not enabled
parent 657394ba
......@@ -9,8 +9,6 @@
/* Begin PBXBuildFile section */
96162C6C1CA71C8700E3A235 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6B1CA71C8700E3A235 /* VideoViewController.swift */; };
96162C6E1CA7274E00E3A235 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */; };
9658F20E1CD6C77D00B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F20D1CD6C77D00B902C1 /* Material.framework */; };
9658F20F1CD6C77D00B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F20D1CD6C77D00B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9663F9321C7A744600AF0965 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9311C7A744600AF0965 /* AppDelegate.swift */; };
9663F9341C7A744600AF0965 /* RecommendationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9663F9331C7A744600AF0965 /* RecommendationViewController.swift */; };
9663F9391C7A744600AF0965 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9663F9381C7A744600AF0965 /* Assets.xcassets */; };
......@@ -30,7 +28,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9658F20F1CD6C77D00B902C1 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -40,7 +37,6 @@
/* Begin PBXFileReference section */
96162C6B1CA71C8700E3A235 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
96162C6D1CA7274E00E3A235 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
9658F20D1CD6C77D00B902C1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
9663F92E1C7A744600AF0965 /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
9663F9311C7A744600AF0965 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9663F9331C7A744600AF0965 /* RecommendationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendationViewController.swift; sourceTree = "<group>"; };
......@@ -60,7 +56,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9658F20E1CD6C77D00B902C1 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -70,7 +65,6 @@
9663F9251C7A744500AF0965 = {
isa = PBXGroup;
children = (
9658F20D1CD6C77D00B902C1 /* Material.framework */,
9663F9301C7A744600AF0965 /* App */,
9663F92F1C7A744600AF0965 /* Products */,
);
......
......@@ -41,27 +41,21 @@ class AppNavigationController: NavigationController {
prepareNavigationBar()
}
/**
Uncomment the code to set a statusBar that is colored, different
from the NavigationBar. Note, if using the .CenterRadialBeyondBounds
pulseAnimation value, it will cover the animation radial effect.
*/
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
// statusBarView?.hidden = MaterialDevice.statusBarHidden
statusBarView?.hidden = MaterialDevice.statusBarHidden
}
/// Prepares the statusBarView
private func prepareStatusBarView() {
// statusBarView = MaterialView()
// statusBarView!.backgroundColor = MaterialColor.blue.darken2
statusBarView = MaterialView()
statusBarView!.backgroundColor = MaterialColor.blue.darken2
// view.addSubview(statusBarView!)
// statusBarView!.translatesAutoresizingMaskIntoConstraints = false
// MaterialLayout.alignFromTop(view, child: statusBarView!)
// MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
// MaterialLayout.height(view, child: statusBarView!, height: 20)
view.addSubview(statusBarView!)
statusBarView!.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: statusBarView!)
MaterialLayout.alignToParentHorizontally(view, child: statusBarView!)
MaterialLayout.height(view, child: statusBarView!, height: 20)
}
/// Prepares the navigationBar
......
......@@ -7,8 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
9658F2111CD6CDD700B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2101CD6CDD700B902C1 /* Material.framework */; };
9658F2121CD6CDD700B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2101CD6CDD700B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96DB1C5F1C14AA2800825BE6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */; };
96DB1C611C14AA2800825BE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C601C14AA2800825BE6 /* ViewController.swift */; };
96DB1C661C14AA2800825BE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96DB1C651C14AA2800825BE6 /* Assets.xcassets */; };
......@@ -22,7 +20,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9658F2121CD6CDD700B902C1 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9658F2101CD6CDD700B902C1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
96DB1C5B1C14AA2800825BE6 /* MaterialPulseView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialPulseView.app; sourceTree = BUILT_PRODUCTS_DIR; };
96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96DB1C601C14AA2800825BE6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9658F2111CD6CDD700B902C1 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -54,7 +49,6 @@
96DB1C521C14AA2800825BE6 = {
isa = PBXGroup;
children = (
9658F2101CD6CDD700B902C1 /* Material.framework */,
96DB1C5D1C14AA2800825BE6 /* MaterialPulseView */,
96DB1C5C1C14AA2800825BE6 /* Products */,
);
......
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
9658F21F1CD7ACD600B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F21E1CD7ACD600B902C1 /* Material.framework */; };
9658F2201CD7ACD600B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F21E1CD7ACD600B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96E5E4671CC1E5EC0054837B /* PurpleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E4661CC1E5EC0054837B /* PurpleViewController.swift */; };
96E5E4691CC1E6130054837B /* OrangeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E4681CC1E6130054837B /* OrangeViewController.swift */; };
96E5E46B1CC1E8FB0054837B /* AppLeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96E5E46A1CC1E8FB0054837B /* AppLeftViewController.swift */; };
......@@ -25,6 +27,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9658F2201CD7ACD600B902C1 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -32,6 +35,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9658F21E1CD7ACD600B902C1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
9663F9651C7ADCB600AF0965 /* SideNavigationController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SideNavigationController.app; sourceTree = BUILT_PRODUCTS_DIR; };
96E5E4661CC1E5EC0054837B /* PurpleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PurpleViewController.swift; sourceTree = "<group>"; };
96E5E4681CC1E6130054837B /* OrangeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrangeViewController.swift; sourceTree = "<group>"; };
......@@ -50,6 +54,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9658F21F1CD7ACD600B902C1 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -59,6 +64,7 @@
9663F95C1C7ADCB600AF0965 = {
isa = PBXGroup;
children = (
9658F21E1CD7ACD600B902C1 /* Material.framework */,
96F2F1FC1C97A68800A5FE27 /* SideNavigationController */,
9663F9661C7ADCB600AF0965 /* Products */,
);
......
......@@ -7,8 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
9658F2141CD6D82000B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2131CD6D82000B902C1 /* Material.framework */; };
9658F2151CD6D82000B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2131CD6D82000B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
966F57A11C226BAA009185B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A01C226BAA009185B7 /* AppDelegate.swift */; };
966F57A31C226BAA009185B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966F57A21C226BAA009185B7 /* ViewController.swift */; };
966F57A81C226BAA009185B7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 966F57A71C226BAA009185B7 /* Assets.xcassets */; };
......@@ -22,7 +20,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9658F2151CD6D82000B902C1 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9658F2131CD6D82000B902C1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
966F579D1C226BAA009185B7 /* TextField.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextField.app; sourceTree = BUILT_PRODUCTS_DIR; };
966F57A01C226BAA009185B7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
966F57A21C226BAA009185B7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9658F2141CD6D82000B902C1 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -54,7 +49,6 @@
966F57941C226BAA009185B7 = {
isa = PBXGroup;
children = (
9658F2131CD6D82000B902C1 /* Material.framework */,
966F579F1C226BAA009185B7 /* TextField */,
966F579E1C226BAA009185B7 /* Products */,
);
......
......@@ -410,9 +410,7 @@ public class MaterialButton : UIButton {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : point!
if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialButton = self {
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
......
......@@ -515,9 +515,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : point!
if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialCollectionViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
......
......@@ -57,9 +57,7 @@ public class MaterialPulseView : MaterialView {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : point!
if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialPulseView = self {
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
......
......@@ -365,9 +365,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : point!
if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialTableViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
......
......@@ -73,8 +73,11 @@ public class NavigationController : UINavigationController, UIGestureRecognizerD
super.viewWillAppear(animated)
if let v: UIGestureRecognizer = interactivePopGestureRecognizer {
if let x: SideNavigationController = sideNavigationController {
if let p: UIPanGestureRecognizer = x.panGesture {
p.requireGestureRecognizerToFail(v)
if let l: UIPanGestureRecognizer = x.panLeftViewGesture {
l.requireGestureRecognizerToFail(v)
}
if let r: UIPanGestureRecognizer = x.panRightViewGesture {
r.requireGestureRecognizerToFail(v)
}
}
}
......
......@@ -125,15 +125,27 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
/**
A UIPanGestureRecognizer property internally used for the
pan gesture.
leftView pan gesture.
*/
internal private(set) var panGesture: UIPanGestureRecognizer?
internal private(set) var panLeftViewGesture: UIPanGestureRecognizer?
/**
A UIPanGestureRecognizer property internally used for the
rightView pan gesture.
*/
internal private(set) var panRightViewGesture: UIPanGestureRecognizer?
/**
A UITapGestureRecognizer property internally used for the
leftView tap gesture.
*/
internal private(set) var tapLeftViewGesture: UITapGestureRecognizer?
/**
A UITapGestureRecognizer property internally used for the
tap gesture.
rightView tap gesture.
*/
internal private(set) var tapGesture: UITapGestureRecognizer?
internal private(set) var tapRightViewGesture: UITapGestureRecognizer?
/**
A CGFloat property that accesses the leftView threshold of
......@@ -143,7 +155,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
leftView is closed. The leftViewThreshold is always at half
the width of the leftView.
*/
@IBInspectable public var leftThreshold: CGFloat?
@IBInspectable public var leftThreshold: CGFloat = 32
private var leftViewThreshold: CGFloat = 0
/**
......@@ -154,7 +166,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
rightView is opened. The rightViewThreshold is always at half
the width of the rightView.
*/
@IBInspectable public var rightThreshold: CGFloat?
@IBInspectable public var rightThreshold: CGFloat = 32
private var rightViewThreshold: CGFloat = 0
/// Sets the animation type for the statusBar when hiding.
......@@ -210,13 +222,29 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
A Boolean property that enables and disables the leftView from
opening and closing. Defaults to true.
*/
@IBInspectable public var enabledLeftView: Bool = true
@IBInspectable public var enabledLeftView: Bool = true {
didSet {
if enabledLeftView {
prepareLeftViewGestures()
} else {
removeLeftViewGestures()
}
}
}
/**
A Boolean property that enables and disables the rightView from
opening and closing. Defaults to true.
*/
@IBInspectable public var enabledRightView: Bool = true
@IBInspectable public var enabledRightView: Bool = true {
didSet {
if enabledRightView {
prepareRightViewGestures()
} else {
removeRightViewGestures()
}
}
}
/**
A Boolean property that triggers the status bar to be hidden
......@@ -540,7 +568,6 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if let v: MaterialView = leftView {
hideStatusBar()
showView(v)
delegate?.sideNavigationWillOpen?(self, position: .Left)
rootViewController.view.alpha = 0.5
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
......@@ -564,7 +591,6 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if let v: MaterialView = rightView {
hideStatusBar()
showView(v)
delegate?.sideNavigationWillOpen?(self, position: .Right)
rootViewController.view.alpha = 0.5
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
......@@ -586,6 +612,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
public func closeLeftView(velocity: CGFloat = 0) {
if enabledLeftView {
if let v: MaterialView = leftView {
showStatusBar()
delegate?.sideNavigationWillClose?(self, position: .Left)
rootViewController.view.alpha = 1
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
......@@ -593,7 +620,6 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
v.position.x = -v.width / 2
}) { [unowned self] _ in
self.hideView(v)
self.toggleStatusBar()
self.delegate?.sideNavigationDidClose?(self, position: .Left)
}
}
......@@ -609,6 +635,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
public func closeRightView(velocity: CGFloat = 0) {
if enabledRightView {
if let v: MaterialView = rightView {
showStatusBar()
delegate?.sideNavigationWillClose?(self, position: .Right)
rootViewController.view.alpha = 1
UIView.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
......@@ -616,7 +643,6 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
v.position.x = self.view.bounds.width + v.width / 2
}) { [unowned self] _ in
self.hideView(v)
self.toggleStatusBar()
self.delegate?.sideNavigationDidClose?(self, position: .Right)
}
}
......@@ -630,91 +656,110 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
- Returns: A Boolean of whether to continue the gesture or not.
*/
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if gestureRecognizer == panGesture {
return opened || isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(touch.locationInView(view))
if !openedRightView && gestureRecognizer == panLeftViewGesture && (openedLeftView || isPointContainedWithinLeftThreshold(touch.locationInView(view))) {
return true
}
if !openedLeftView && gestureRecognizer == panRightViewGesture && (openedRightView || isPointContainedWithinRighThreshold(touch.locationInView(view))) {
return true
}
if openedLeftView && gestureRecognizer == tapLeftViewGesture {
return true
}
return opened && gestureRecognizer == tapGesture
if openedRightView && gestureRecognizer == tapRightViewGesture {
return true
}
return false
}
/**
A method that is fired when the pan gesture is recognized
for the SideNavigationController.
for the leftView.
- Parameter recognizer: A UIPanGestureRecognizer that is
passed to the handler when recognized.
*/
@objc(handlePanGesture:)
internal func handlePanGesture(recognizer: UIPanGestureRecognizer) {
// Deterine which view to pan.
if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRightViewThreshold(recognizer.locationInView(view))) {
if let v: MaterialView = rightView {
internal func handleLeftViewPanGesture(recognizer: UIPanGestureRecognizer) {
if enabledLeftView && (openedLeftView || !openedRightView && isPointContainedWithinLeftThreshold(recognizer.locationInView(view))) {
if let v: MaterialView = leftView {
let point: CGPoint = recognizer.locationInView(view)
// Animate the panel.
switch recognizer.state {
case .Began:
originalX = v.position.x
hideStatusBar()
showView(v)
delegate?.sideNavigationPanDidBegin?(self, point: point, position: .Right)
delegate?.sideNavigationPanDidBegin?(self, point: point, position: .Left)
case .Changed:
let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x
v.position.x = originalX + translationX < view.bounds.width - (w / 2) ? view.bounds.width - (w / 2) : originalX + translationX
v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
let a: CGFloat = 1 - (view.bounds.width - v.position.x) / v.width
let a: CGFloat = 1 - v.position.x / v.width
rootViewController.view.alpha = 0.5 < a ? a : 0.5
delegate?.sideNavigationPanDidChange?(self, point: point, position: .Right)
if v.position.x >= leftThreshold {
hideStatusBar()
}
delegate?.sideNavigationPanDidChange?(self, point: point, position: .Left)
case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationPanDidEnd?(self, point: point, position: .Right)
delegate?.sideNavigationPanDidEnd?(self, point: point, position: .Left)
if v.x >= rightViewThreshold || x > 1000 {
closeRightView(x)
if v.x <= -leftViewWidth + leftViewThreshold || x < -1000 {
closeLeftView(x)
} else {
openRightView(x)
openLeftView(x)
}
case .Possible:break
}
}
} else if enabledLeftView && (openedLeftView || !openedRightView && isPointContainedWithinLeftViewThreshold(recognizer.locationInView(view))) {
if let v: MaterialView = leftView {
}
}
/**
A method that is fired when the pan gesture is recognized
for the rightView.
- Parameter recognizer: A UIPanGestureRecognizer that is
passed to the handler when recognized.
*/
internal func handleRightViewPanGesture(recognizer: UIPanGestureRecognizer) {
if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRighThreshold(recognizer.locationInView(view))) {
if let v: MaterialView = rightView {
let point: CGPoint = recognizer.locationInView(view)
// Animate the panel.
switch recognizer.state {
case .Began:
originalX = v.position.x
hideStatusBar()
showView(v)
delegate?.sideNavigationPanDidBegin?(self, point: point, position: .Left)
delegate?.sideNavigationPanDidBegin?(self, point: point, position: .Right)
case .Changed:
let w: CGFloat = v.width
let translationX: CGFloat = recognizer.translationInView(v).x
v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
v.position.x = originalX + translationX < view.bounds.width - (w / 2) ? view.bounds.width - (w / 2) : originalX + translationX
let a: CGFloat = 1 - v.position.x / v.width
let a: CGFloat = 1 - (view.bounds.width - v.position.x) / v.width
rootViewController.view.alpha = 0.5 < a ? a : 0.5
delegate?.sideNavigationPanDidChange?(self, point: point, position: .Left)
if v.position.x <= view.bounds.width - rightThreshold {
hideStatusBar()
}
delegate?.sideNavigationPanDidChange?(self, point: point, position: .Right)
case .Ended, .Cancelled, .Failed:
let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationPanDidEnd?(self, point: point, position: .Left)
delegate?.sideNavigationPanDidEnd?(self, point: point, position: .Right)
if v.x <= -leftViewWidth + leftViewThreshold || x < -1000 {
closeLeftView(x)
if v.x >= rightViewThreshold || x > 1000 {
closeRightView(x)
} else {
openLeftView(x)
openRightView(x)
}
case .Possible:break
}
......@@ -724,12 +769,11 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
/**
A method that is fired when the tap gesture is recognized
for the SideNavigationController.
for the leftView.
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
*/
@objc(handleTapGesture:)
internal func handleTapGesture(recognizer: UITapGestureRecognizer) {
internal func handleLeftViewTapGesture(recognizer: UITapGestureRecognizer) {
if openedLeftView {
if let v: MaterialView = leftView {
delegate?.sideNavigationDidTap?(self, point: recognizer.locationInView(view), position: .Left)
......@@ -738,6 +782,15 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
}
}
}
}
/**
A method that is fired when the tap gesture is recognized
for the rightView.
- Parameter recognizer: A UITapGestureRecognizer that is
passed to the handler when recognized.
*/
internal func handleRightViewTapGesture(recognizer: UITapGestureRecognizer) {
if openedRightView {
if let v: MaterialView = rightView {
delegate?.sideNavigationDidTap?(self, point: recognizer.locationInView(view), position: .Right)
......@@ -763,7 +816,8 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
prepareRightView()
prepareLeftViewController()
prepareRightViewController()
prepareGestures()
prepareLeftViewGestures()
prepareRightViewGestures()
}
/// A method that prepares the rootViewController.
......@@ -843,43 +897,66 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
}
}
/**
A method that prepares the gestures used within the
SideNavigationController.
*/
private func prepareGestures() {
if nil == panGesture {
panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture))
panGesture!.delegate = self
view.addGestureRecognizer(panGesture!)
/// A method that prepares the gestures used within the leftView.
private func prepareLeftViewGestures() {
if nil == panLeftViewGesture {
panLeftViewGesture = UIPanGestureRecognizer(target: self, action: #selector(handleLeftViewPanGesture(_:)))
panLeftViewGesture!.delegate = self
view.addGestureRecognizer(panLeftViewGesture!)
}
if nil == tapGesture {
tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))
tapGesture!.delegate = self
tapGesture!.cancelsTouchesInView = false
view.addGestureRecognizer(tapGesture!)
if nil == tapLeftViewGesture {
tapLeftViewGesture = UITapGestureRecognizer(target: self, action: #selector(handleLeftViewTapGesture(_:)))
tapLeftViewGesture!.delegate = self
tapLeftViewGesture!.cancelsTouchesInView = false
view.addGestureRecognizer(tapLeftViewGesture!)
}
}
/**
A method that removes the passed in pan and tap gesture
recognizers.
*/
private func removeGestures() {
if let v: UIPanGestureRecognizer = panGesture {
/// A method that prepares the gestures used within the rightView.
private func prepareRightViewGestures() {
if nil == panRightViewGesture {
panRightViewGesture = UIPanGestureRecognizer(target: self, action: #selector(handleRightViewPanGesture(_:)))
panRightViewGesture!.delegate = self
view.addGestureRecognizer(panRightViewGesture!)
}
if nil == tapRightViewGesture {
tapRightViewGesture = UITapGestureRecognizer(target: self, action: #selector(handleRightViewTapGesture(_:)))
tapRightViewGesture!.delegate = self
tapRightViewGesture!.cancelsTouchesInView = false
view.addGestureRecognizer(tapRightViewGesture!)
}
}
/// A method that removes the passed in pan and leftView tap gesture recognizers.
private func removeLeftViewGestures() {
if let v: UIPanGestureRecognizer = panLeftViewGesture {
view.removeGestureRecognizer(v)
panGesture = nil
panLeftViewGesture = nil
}
if let v: UITapGestureRecognizer = tapGesture {
if let v: UITapGestureRecognizer = tapLeftViewGesture {
view.removeGestureRecognizer(v)
tapGesture = nil
tapLeftViewGesture = nil
}
}
/// A method that removes the passed in pan and rightView tap gesture recognizers.
private func removeRightViewGestures() {
if let v: UIPanGestureRecognizer = panRightViewGesture {
view.removeGestureRecognizer(v)
panRightViewGesture = nil
}
if let v: UITapGestureRecognizer = tapRightViewGesture {
view.removeGestureRecognizer(v)
tapRightViewGesture = nil
}
}
/// Shows the statusBar.
private func showStatusBar() {
willHideStatusBar = false
if MaterialDevice.statusBarHidden {
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in
self?.setNeedsStatusBarAppearanceUpdate()
......@@ -887,10 +964,12 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
})
delegate?.sideNavigationStatusBarHiddenState?(self, hidden: false)
}
}
/// Hides the statusBar.
private func hideStatusBar() {
if enableHideStatusbar {
if !MaterialDevice.statusBarHidden {
willHideStatusBar = true
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in
......@@ -900,6 +979,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
delegate?.sideNavigationStatusBarHiddenState?(self, hidden: true)
}
}
}
/// Toggles the statusBar
private func toggleStatusBar() {
......@@ -919,8 +999,8 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
- Returns: A Boolean of the result, true if yes, false
otherwise.
*/
private func isPointContainedWithinLeftViewThreshold(point: CGPoint) -> Bool {
return point.x <= leftViewThreshold
private func isPointContainedWithinLeftThreshold(point: CGPoint) -> Bool {
return point.x <= leftThreshold
}
/**
......@@ -932,8 +1012,8 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
- Returns: A Boolean of the result, true if yes, false
otherwise.
*/
private func isPointContainedWithinRightViewThreshold(point: CGPoint) -> Bool {
return point.x >= rightViewThreshold
private func isPointContainedWithinRighThreshold(point: CGPoint) -> Bool {
return point.x >= view.bounds.width - rightThreshold
}
/**
......@@ -977,7 +1057,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if let v: MaterialView = leftView {
v.width = leftViewWidth
v.height = view.bounds.height
leftViewThreshold = nil == leftThreshold ? leftViewWidth / 2 : leftThreshold!
leftViewThreshold = leftViewWidth / 2
if let vc: UIViewController = leftViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
......@@ -988,7 +1068,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if let v: MaterialView = rightView {
v.width = rightViewWidth
v.height = view.bounds.height
rightViewThreshold = nil == rightThreshold ? view.bounds.width - rightViewWidth / 2 : view.bounds.width - rightThreshold!
rightViewThreshold = view.bounds.width - rightViewWidth / 2
if let vc: UIViewController = rightViewController {
vc.view.frame.size.width = v.width
vc.view.frame.size.height = v.height
......
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