Commit 69986a27 by Daniel Dahan

working pan for both leftView and rightView

parent 18a4375b
...@@ -347,7 +347,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -347,7 +347,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
v.width = self.rightViewWidth v.width = self.rightViewWidth
v.height = self.view.bounds.height v.height = self.view.bounds.height
} }
rightViewThreshold = rightViewWidth / 2 rightViewThreshold = view.bounds.width - rightViewWidth / 2
rightViewController?.view.frame.size.width = v.width rightViewController?.view.frame.size.width = v.width
rightViewController?.view.frame.size.height = v.height rightViewController?.view.frame.size.height = v.height
rightViewController?.view.center = CGPointMake(v.width / 2, v.height / 2) rightViewController?.view.center = CGPointMake(v.width / 2, v.height / 2)
...@@ -648,7 +648,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -648,7 +648,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool { public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if gestureRecognizer == panGesture { if gestureRecognizer == panGesture {
return opened || enabled && (isPointContainedWithinLeftViewThreshold(touch.locationInView(view)) || isPointContainedWithinRightViewThreshold(touch.locationInView(view))) return 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)
...@@ -669,6 +669,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -669,6 +669,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRightViewThreshold(recognizer.locationInView(view))) { if enabledRightView && (openedRightView || !openedLeftView && isPointContainedWithinRightViewThreshold(recognizer.locationInView(view))) {
currentView = rightView currentView = rightView
if let v: MaterialView = currentView { if let v: MaterialView = currentView {
let point: CGPoint = recognizer.locationInView(view)
// Animate the panel. // Animate the panel.
switch recognizer.state { switch recognizer.state {
case .Began: case .Began:
...@@ -676,23 +678,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -676,23 +678,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
originalPosition = v.position originalPosition = v.position
toggleStatusBar(true) toggleStatusBar(true)
showDepth() showDepth()
delegate?.sideNavigationViewPanDidBegin?(self, point: recognizer.locationInView(view))
delegate?.sideNavigationViewPanDidBegin?(self, point: point)
case .Changed: case .Changed:
let translation: CGPoint = recognizer.translationInView(v)
let w: CGFloat = v.width let w: CGFloat = v.width
let originalX: CGFloat = originalPosition.x
let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
print("OX \(self.originalPosition.x) TX \(translation.x)") v.position.x = originalX + translationX < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : originalX + translationX
v.position.x = self.originalPosition.x + translation.x < self.view.bounds.width - (w / 2) ? self.view.bounds.width - (w / 2) : self.originalPosition.x + translation.x self.delegate?.sideNavigationViewPanDidChange?(self, point: point)
self.delegate?.sideNavigationViewPanDidChange?(self, point: recognizer.locationInView(self.view))
} }
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let point: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: recognizer.locationInView(view)) delegate?.sideNavigationViewPanDidEnd?(self, point: point)
if v.x <= CGFloat(floor(-rightViewWidth)) + rightViewThreshold || point.x <= -1000 { if v.x >= rightViewThreshold {
closeRightView(x) closeRightView(x)
} else { } else {
openRightView(x) openRightView(x)
...@@ -703,6 +706,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -703,6 +706,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
} else if enabledLeftView { } else if enabledLeftView {
currentView = leftView currentView = leftView
if let v: MaterialView = currentView { if let v: MaterialView = currentView {
let point: CGPoint = recognizer.locationInView(view)
// Animate the panel. // Animate the panel.
switch recognizer.state { switch recognizer.state {
case .Began: case .Began:
...@@ -710,22 +715,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -710,22 +715,24 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
originalPosition = v.position originalPosition = v.position
toggleStatusBar(true) toggleStatusBar(true)
showDepth() showDepth()
delegate?.sideNavigationViewPanDidBegin?(self, point: recognizer.locationInView(view))
delegate?.sideNavigationViewPanDidBegin?(self, point: point)
case .Changed: case .Changed:
let translation: CGPoint = recognizer.translationInView(v)
let w: CGFloat = v.width let w: CGFloat = v.width
let originalX: CGFloat = originalPosition.x
let translationX: CGFloat = recognizer.translationInView(v).x
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
v.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x v.position.x = originalX + translationX > (w / 2) ? (w / 2) : originalX + translationX
self.delegate?.sideNavigationViewPanDidChange?(self, point: recognizer.locationInView(self.view)) self.delegate?.sideNavigationViewPanDidChange?(self, point: point)
} }
case .Ended, .Cancelled, .Failed: case .Ended, .Cancelled, .Failed:
let point: CGPoint = recognizer.velocityInView(recognizer.view) let p: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0 let x: CGFloat = p.x >= 1000 || p.x <= -1000 ? p.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: recognizer.locationInView(view)) delegate?.sideNavigationViewPanDidEnd?(self, point: point)
if v.x <= CGFloat(floor(-leftViewWidth)) + leftViewThreshold || point.x <= -1000 { if v.x <= -leftViewWidth + leftViewThreshold {
closeLeftView(x) closeLeftView(x)
} else { } else {
openLeftView(x) openLeftView(x)
...@@ -919,7 +926,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -919,7 +926,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
otherwise. otherwise.
*/ */
private func isPointContainedWithinRightViewThreshold(point: CGPoint) -> Bool { private func isPointContainedWithinRightViewThreshold(point: CGPoint) -> Bool {
return CGRectContainsPoint(CGRectMake(0, 0, view.bounds.width - rightViewThreshold, view.frame.height), point) return CGRectContainsPoint(CGRectMake(view.bounds.width - rightViewThreshold, 0, rightViewThreshold, 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