Commit b5cc6a58 by Daniel Dahan

fixed issue with tap gesture recognizer

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