Commit 7a577efb by Daniel Dahan

tap working for left and right views

parent a02d99b0
...@@ -108,6 +108,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -108,6 +108,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private var originalPosition: CGPoint = CGPointZero private var originalPosition: CGPoint = CGPointZero
/** /**
A UIView property that is used internally to track
the currentView, either leftView or rightView.
*/
private var currentView: UIView?
/**
A UIPanGestureRecognizer property internally used for the A UIPanGestureRecognizer property internally used for the
pan gesture. pan gesture.
*/ */
...@@ -178,9 +184,34 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -178,9 +184,34 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/ */
public var enabled: Bool = true { public var enabled: Bool = true {
didSet { didSet {
if enabled { enabledLeftView = enabled
enabledRightView = enabled
}
}
/**
A Boolean property that enables and disables the leftView from
opening and closing. Defaults to true.
*/
public var enabledLeftView: Bool = true {
didSet {
if enabledLeftView {
prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:") prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:")
} else { } else if !enabledRightView {
removeGestures(&panGesture, tap: &tapGesture)
}
}
}
/**
A Boolean property that enables and disables the rightView from
opening and closing. Defaults to true.
*/
public var enabledRightView: Bool = true {
didSet {
if enabledRightView {
prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:")
} else if !enabledLeftView {
removeGestures(&panGesture, tap: &tapGesture) removeGestures(&panGesture, tap: &tapGesture)
} }
} }
...@@ -518,18 +549,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -518,18 +549,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftView. Defaults to 0. leftView. Defaults to 0.
*/ */
public func openLeftView(velocity: CGFloat = 0) { public func openLeftView(velocity: CGFloat = 0) {
toggleStatusBar(true) if enabledLeftView {
backdropLayer.hidden = false toggleStatusBar(true)
backdropLayer.hidden = false
if let v: MaterialView = leftView {
delegate?.sideNavigationViewWillOpen?(self) if let v: MaterialView = leftView {
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), delegate?.sideNavigationViewWillOpen?(self)
animations: { MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
v.position = CGPointMake(v.width / 2, v.height / 2) animations: {
}) { [unowned self] in v.position = CGPointMake(v.width / 2, v.height / 2)
self.userInteractionEnabled = false }) { [unowned self] in
self.showLeftViewDepth() self.userInteractionEnabled = false
self.delegate?.sideNavigationViewDidOpen?(self) self.showLeftViewDepth()
self.delegate?.sideNavigationViewDidOpen?(self)
}
} }
} }
} }
...@@ -541,18 +574,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -541,18 +574,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftView. Defaults to 0. leftView. Defaults to 0.
*/ */
public func openRightView(velocity: CGFloat = 0) { public func openRightView(velocity: CGFloat = 0) {
toggleStatusBar(true) if enabledRightView {
backdropLayer.hidden = false toggleStatusBar(true)
backdropLayer.hidden = false
if let v: MaterialView = rightView {
delegate?.sideNavigationViewWillOpen?(self) if let v: MaterialView = rightView {
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), delegate?.sideNavigationViewWillOpen?(self)
animations: { MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2) animations: {
}) { [unowned self] in v.position = CGPointMake(self.view.bounds.width - v.width / 2, v.height / 2)
self.userInteractionEnabled = false }) { [unowned self] in
self.showRightViewDepth() self.userInteractionEnabled = false
self.delegate?.sideNavigationViewDidOpen?(self) self.showRightViewDepth()
self.delegate?.sideNavigationViewDidOpen?(self)
}
} }
} }
} }
...@@ -564,18 +599,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -564,18 +599,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftView. Defaults to 0. leftView. Defaults to 0.
*/ */
public func closeLeftView(velocity: CGFloat = 0) { public func closeLeftView(velocity: CGFloat = 0) {
toggleStatusBar(false) if enabledLeftView {
backdropLayer.hidden = true toggleStatusBar(false)
backdropLayer.hidden = true
if let v: MaterialView = leftView {
delegate?.sideNavigationViewWillClose?(self) if let v: MaterialView = leftView {
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), delegate?.sideNavigationViewWillClose?(self)
animations: { MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
v.position = CGPointMake(-v.width / 2, v.height / 2) animations: {
}) { [unowned self] in v.position = CGPointMake(-v.width / 2, v.height / 2)
self.userInteractionEnabled = true }) { [unowned self] in
self.hideLeftViewDepth() self.userInteractionEnabled = true
self.delegate?.sideNavigationViewDidClose?(self) self.hideLeftViewDepth()
self.delegate?.sideNavigationViewDidClose?(self)
}
} }
} }
} }
...@@ -587,32 +624,32 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -587,32 +624,32 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftView. Defaults to 0. leftView. Defaults to 0.
*/ */
public func closeRightView(velocity: CGFloat = 0) { public func closeRightView(velocity: CGFloat = 0) {
toggleStatusBar(false) if enabledRightView {
backdropLayer.hidden = true toggleStatusBar(false)
backdropLayer.hidden = true
if let v: MaterialView = rightView {
delegate?.sideNavigationViewWillClose?(self) if let v: MaterialView = rightView {
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), delegate?.sideNavigationViewWillClose?(self)
animations: { MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2) animations: {
}) { [unowned self] in v.position = CGPointMake(self.view.bounds.width + v.width / 2, v.height / 2)
self.userInteractionEnabled = true }) { [unowned self] in
self.hideRightViewDepth() self.userInteractionEnabled = true
self.delegate?.sideNavigationViewDidClose?(self) self.hideRightViewDepth()
self.delegate?.sideNavigationViewDidClose?(self)
}
} }
} }
} }
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool { public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if enabled { if gestureRecognizer == panGesture {
if gestureRecognizer == panGesture { return opened || enabled && (isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(touch.locationInView(view)))
return opened || enabled && isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) }
} if opened && gestureRecognizer == tapGesture {
if opened && gestureRecognizer == tapGesture { let point: CGPoint = touch.locationInView(view)
let point: CGPoint = touch.locationInView(view) delegate?.sideNavigationViewDidTap?(self, point: point)
delegate?.sideNavigationViewDidTap?(self, point: point) return !isPointContainedWithinView(leftView!, point: point) || !isPointContainedWithinView(rightView!, point: point)
return !isPointContainedWithinView(leftView!, point: point) || !isPointContainedWithinView(rightView!, point: point)
}
} }
return false return false
} }
...@@ -627,6 +664,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -627,6 +664,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if enabled { if enabled {
switch recognizer.state { switch recognizer.state {
case .Began: case .Began:
if !opened {
if isPointContainedWithinLeftViewThreshold(recognizer.locationInView(view)) {
}
}
backdropLayer.hidden = false backdropLayer.hidden = false
originalPosition = leftView!.position originalPosition = leftView!.position
toggleStatusBar(true) toggleStatusBar(true)
...@@ -830,6 +872,19 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -830,6 +872,19 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
/** /**
A method that determines whether the passed point is
contained within the bounds of the rightViewThreshold
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 isPointContainedWithinRightViewThreshold(point: CGPoint) -> Bool {
return CGRectContainsPoint(CGRectMake(0, 0, view.bounds.width - rightViewThreshold, view.frame.height), point)
}
/**
A method that determines whether the passed in point is A method that determines whether the passed in point is
contained within the bounds of the passed in container view. contained within the bounds of the passed in container view.
- Parameter container: A UIView that sets the bounds to test - Parameter container: A UIView that sets the bounds to test
......
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