Commit b5414c6b by Daniel Dahan

updating threshold for pan gesture on SideNav

parent e76b1a27
...@@ -111,13 +111,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -111,13 +111,13 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
A UIPanGestureRecognizer property internally used for the A UIPanGestureRecognizer property internally used for the
pan gesture. pan gesture.
*/ */
private var sidePanGesture: UIPanGestureRecognizer? private var panGesture: UIPanGestureRecognizer?
/** /**
A UITapGestureRecognizer property internally used for the A UITapGestureRecognizer property internally used for the
tap gesture. tap gesture.
*/ */
private var sideTapGesture: UITapGestureRecognizer? private var tapGesture: UITapGestureRecognizer?
/** /**
A CAShapeLayer property that is used as the backdrop when A CAShapeLayer property that is used as the backdrop when
...@@ -128,14 +128,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -128,14 +128,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public private(set) lazy var backdropLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var backdropLayer: CAShapeLayer = CAShapeLayer()
/** /**
A CGFloat property that accesses the horizontal threshold of A CGFloat property that accesses the leftView threshold of
the SideNavigationViewController. When the panning gesture has the SideNavigationViewController. When the panning gesture has
ended, if the position is beyond the horizontal threshold, ended, if the position is beyond the threshold,
the leftView is opened, if it is below the threshold, the the leftView is opened, if it is below the threshold, the
leftView is closed. The horizontal threshold is always at half leftView is closed. The leftViewThreshold is always at half
the width of the leftView. the width of the leftView.
*/ */
public private(set) var horizontalThreshold: CGFloat = 0 public private(set) var leftViewThreshold: CGFloat = 0
/**
A CGFloat property that accesses the rightView threshold of
the SideNavigationViewController. When the panning gesture has
ended, if the position is beyond the threshold,
the rightView is closed, if it is below the threshold, the
rightView is opened. The rightViewThreshold is always at half
the width of the rightView.
*/
public private(set) var rightViewThreshold: CGFloat = 0
/** /**
A SideNavigationViewControllerDelegate property used to bind A SideNavigationViewControllerDelegate property used to bind
...@@ -169,10 +179,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -169,10 +179,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public var enabled: Bool = true { public var enabled: Bool = true {
didSet { didSet {
if enabled { if enabled {
removeGestures(&sidePanGesture, tap: &sideTapGesture) removeGestures(&panGesture, tap: &tapGesture)
prepareGestures(&sidePanGesture, panSelector: "handlePanGesture:", tap: &sideTapGesture, tapSelector: "handleTapGesture:") prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:")
} else { } else {
removeGestures(&sidePanGesture, tap: &sideTapGesture) removeGestures(&panGesture, tap: &tapGesture)
} }
} }
} }
...@@ -501,10 +511,10 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -501,10 +511,10 @@ 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 enabled {
if gestureRecognizer == sidePanGesture { if gestureRecognizer == panGesture {
return opened || enabled && isPointContainedWithinRect(touch.locationInView(view)) return enabled && isPointContainedWithinLeftThreshold(touch.locationInView(view))
} }
if opened && gestureRecognizer == sideTapGesture { 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 !isPointContainedWithinViewController(leftView!, point: point) return !isPointContainedWithinViewController(leftView!, point: point)
...@@ -614,8 +624,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -614,8 +624,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} }
prepareLeftViewController() prepareLeftViewController()
removeGestures(&sidePanGesture, tap: &sideTapGesture) removeGestures(&panGesture, tap: &tapGesture)
prepareGestures(&sidePanGesture, panSelector: "handlePanGesture:", tap: &sideTapGesture, tapSelector: "handleTapGesture:") prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:")
} }
/** /**
...@@ -710,7 +720,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -710,7 +720,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
- Returns: A Boolean of the result, true if yes, false - Returns: A Boolean of the result, true if yes, false
otherwise. otherwise.
*/ */
private func isPointContainedWithinRect(point: CGPoint) -> Bool { private func isPointContainedWithinLeftThreshold(point: CGPoint) -> Bool {
return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.frame.height), point) return CGRectContainsPoint(CGRectMake(0, 0, horizontalThreshold, view.frame.height), point)
} }
......
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