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,6 +549,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -518,6 +549,7 @@ 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) {
if enabledLeftView {
toggleStatusBar(true) toggleStatusBar(true)
backdropLayer.hidden = false backdropLayer.hidden = false
...@@ -533,6 +565,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -533,6 +565,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
} }
} }
}
/** /**
A method that opens the rightView. A method that opens the rightView.
...@@ -541,6 +574,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -541,6 +574,7 @@ 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) {
if enabledRightView {
toggleStatusBar(true) toggleStatusBar(true)
backdropLayer.hidden = false backdropLayer.hidden = false
...@@ -556,6 +590,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -556,6 +590,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
} }
} }
}
/** /**
A method that closes the leftView. A method that closes the leftView.
...@@ -564,6 +599,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -564,6 +599,7 @@ 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) {
if enabledLeftView {
toggleStatusBar(false) toggleStatusBar(false)
backdropLayer.hidden = true backdropLayer.hidden = true
...@@ -579,6 +615,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -579,6 +615,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
} }
} }
}
/** /**
A method that closes the rightView. A method that closes the rightView.
...@@ -587,6 +624,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -587,6 +624,7 @@ 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) {
if enabledRightView {
toggleStatusBar(false) toggleStatusBar(false)
backdropLayer.hidden = true backdropLayer.hidden = true
...@@ -602,18 +640,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -602,18 +640,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
} }
} }
}
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)) return opened || enabled && (isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(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