Commit b5cc6a58 by Daniel Dahan

fixed issue with tap gesture recognizer

parent d7cb2f19
...@@ -44,7 +44,7 @@ private struct Item { ...@@ -44,7 +44,7 @@ private struct Item {
var image: UIImage? var image: UIImage?
} }
class MainViewController: UIViewController { class MainViewController: UIViewController, SideNavigationViewControllerDelegate {
/// A tableView used to display Bond entries. /// A tableView used to display Bond entries.
private let tableView: UITableView = UITableView() private let tableView: UITableView = UITableView()
...@@ -70,6 +70,11 @@ class MainViewController: UIViewController { ...@@ -70,6 +70,11 @@ class MainViewController: UIViewController {
the MainViewController and SideViewController. the MainViewController and SideViewController.
*/ */
sideNavigationViewController?.setLeftViewWidth(view.bounds.width - 88, hidden: true, animated: false) sideNavigationViewController?.setLeftViewWidth(view.bounds.width - 88, hidden: true, animated: false)
sideNavigationViewController?.delegate = self
}
func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint) {
print(point)
} }
/** /**
...@@ -80,6 +85,14 @@ class MainViewController: UIViewController { ...@@ -80,6 +85,14 @@ class MainViewController: UIViewController {
sideNavigationViewController?.openLeftView() sideNavigationViewController?.openLeftView()
} }
/**
Handles the search button click, which opens the
SideNavigationViewController.
*/
func handleSearchButton() {
sideNavigationViewController?.openRightView()
}
/// Prepares view. /// Prepares view.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.white view.backgroundColor = MaterialColor.white
...@@ -153,6 +166,7 @@ class MainViewController: UIViewController { ...@@ -153,6 +166,7 @@ class MainViewController: UIViewController {
searchButton.setImage(img2, forState: .Normal) searchButton.setImage(img2, forState: .Normal)
searchButton.setImage(img2, forState: .Highlighted) searchButton.setImage(img2, forState: .Highlighted)
searchButton.tintColor = MaterialColor.cyan.darken4 searchButton.tintColor = MaterialColor.cyan.darken4
searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
// Add searchButton to right side. // Add searchButton to right side.
navigationBarView.rightButtons = [searchButton] navigationBarView.rightButtons = [searchButton]
......
...@@ -53,13 +53,13 @@ class RightViewController: UIViewController { ...@@ -53,13 +53,13 @@ class RightViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareItems() prepareItems()
prepareProfileView() // prepareProfileView()
prepareTableView() // prepareTableView()
} }
/// General preparation statements. /// General preparation statements.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.clear view.backgroundColor = MaterialColor.black
} }
override func viewWillAppear(animated: Bool) { override func viewWillAppear(animated: Bool) {
......
...@@ -283,9 +283,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -283,9 +283,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public override func viewWillLayoutSubviews() { public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
MaterialAnimation.animationDisabled { [unowned self] in
self.backdropLayer.frame = self.view.bounds
}
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
MaterialAnimation.animationDisabled { [unowned self] in MaterialAnimation.animationDisabled { [unowned self] in
self.backdropLayer.frame = self.view.bounds
v.width = self.leftViewWidth v.width = self.leftViewWidth
v.height = self.view.bounds.height v.height = self.view.bounds.height
} }
...@@ -294,6 +297,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -294,6 +297,17 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
leftViewController?.view.frame.size.height = v.height leftViewController?.view.frame.size.height = v.height
leftViewController?.view.center = CGPointMake(v.width / 2, v.height / 2) leftViewController?.view.center = CGPointMake(v.width / 2, v.height / 2)
} }
if let v: MaterialView = rightView {
MaterialAnimation.animationDisabled { [unowned self] in
v.width = self.rightViewWidth
v.height = self.view.bounds.height
}
rightViewThreshold = rightViewWidth / 2
rightViewController?.view.frame.size.width = v.width
rightViewController?.view.frame.size.height = v.height
rightViewController?.view.center = CGPointMake(v.width / 2, v.height / 2)
}
} }
/** /**
...@@ -521,7 +535,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -521,7 +535,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate?.sideNavigationViewWillOpen?(self) delegate?.sideNavigationViewWillOpen?(self)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position = CGPointMake(v.width / 2, v.height / 2) v.position = CGPointMake(-v.width / 2, v.height / 2)
}) { [unowned self] in }) { [unowned self] in
self.userInteractionEnabled = false self.userInteractionEnabled = false
self.showRightViewDepth() self.showRightViewDepth()
...@@ -597,33 +611,35 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -597,33 +611,35 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
passed to the handler when recognized. passed to the handler when recognized.
*/ */
internal func handlePanGesture(recognizer: UIPanGestureRecognizer) { internal func handlePanGesture(recognizer: UIPanGestureRecognizer) {
switch recognizer.state { if enabled {
case .Began: switch recognizer.state {
backdropLayer.hidden = false case .Began:
originalPosition = leftView!.position backdropLayer.hidden = false
toggleStatusBar(true) originalPosition = leftView!.position
showLeftViewDepth() toggleStatusBar(true)
delegate?.sideNavigationViewPanDidBegin?(self, point: leftView!.position) showLeftViewDepth()
case .Changed: delegate?.sideNavigationViewPanDidBegin?(self, point: leftView!.position)
let translation: CGPoint = recognizer.translationInView(leftView) case .Changed:
let w: CGFloat = leftView!.width let translation: CGPoint = recognizer.translationInView(leftView)
let w: CGFloat = leftView!.width
MaterialAnimation.animationDisabled { [unowned self] in
self.leftView!.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x MaterialAnimation.animationDisabled { [unowned self] in
self.delegate?.sideNavigationViewPanDidChange?(self, point: self.leftView!.position) self.leftView!.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x
} self.delegate?.sideNavigationViewPanDidChange?(self, point: self.leftView!.position)
case .Ended, .Cancelled, .Failed: }
let point: CGPoint = recognizer.velocityInView(recognizer.view) case .Ended, .Cancelled, .Failed:
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0 let point: CGPoint = recognizer.velocityInView(recognizer.view)
let x: CGFloat = point.x >= 1000 || point.x <= -1000 ? point.x : 0
delegate?.sideNavigationViewPanDidEnd?(self, point: leftView!.position)
delegate?.sideNavigationViewPanDidEnd?(self, point: leftView!.position)
if leftView!.x <= CGFloat(floor(-leftViewWidth)) + leftViewThreshold || point.x <= -1000 {
closeLeftView(x) if leftView!.x <= CGFloat(floor(-leftViewWidth)) + leftViewThreshold || point.x <= -1000 {
} else { closeLeftView(x)
openLeftView(x) } else {
openLeftView(x)
}
case .Possible:break
} }
case .Possible:break
} }
} }
...@@ -646,6 +662,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -646,6 +662,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
prepareLeftView() prepareLeftView()
prepareRightView() prepareRightView()
prepareLeftViewController() prepareLeftViewController()
prepareRightViewController()
prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:") prepareGestures(&panGesture, panSelector: "handlePanGesture:", tap: &tapGesture, tapSelector: "handleTapGesture:")
} }
...@@ -665,7 +682,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -665,7 +682,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/// A method that prepares the rightViewController. /// A method that prepares the rightViewController.
private func prepareRightViewController() { private func prepareRightViewController() {
if let v: MaterialView = leftView { if let v: MaterialView = rightView {
rightViewController?.view.clipsToBounds = true rightViewController?.view.clipsToBounds = true
prepareViewControllerWithinContainer(rightViewController, container: v) prepareViewControllerWithinContainer(rightViewController, container: v)
} }
...@@ -690,7 +707,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -690,7 +707,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
private func prepareRightView() { private func prepareRightView() {
if nil != rightViewController { if nil != rightViewController {
rightView = MaterialView() rightView = MaterialView()
rightView!.frame = CGRectMake(0, 0, rightViewWidth, view.frame.height) rightView!.frame = CGRectMake(view.bounds.width, 0, rightViewWidth, view.frame.height)
rightView!.backgroundColor = MaterialColor.clear rightView!.backgroundColor = MaterialColor.clear
view.addSubview(leftView!) view.addSubview(leftView!)
...@@ -746,7 +763,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -746,7 +763,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
view.addGestureRecognizer(pan!) view.addGestureRecognizer(pan!)
} }
if nil == pan { if nil == tap {
tap = UITapGestureRecognizer(target: self, action: tapSelector) tap = UITapGestureRecognizer(target: self, action: tapSelector)
tap!.delegate = self tap!.delegate = self
view.addGestureRecognizer(tap!) view.addGestureRecognizer(tap!)
......
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