Commit 888f717c by Daniel Dahan

added delegation examples to Example SideNav app

parent fd4d8871
......@@ -70,6 +70,7 @@ class MainViewController: UIViewController {
the MainViewController and SideViewController.
*/
sideNavigationViewController?.setLeftViewWidth(view.bounds.width - 88, hidden: true, animated: false)
sideNavigationViewController?.delegate = self
}
/**
......@@ -248,3 +249,70 @@ extension MainViewController: UITableViewDelegate {
return 48
}
}
/// SideNavigationViewControllerDelegate methods.
extension MainViewController: SideNavigationViewControllerDelegate {
/**
An optional delegation method that is fired before the
SideNavigationViewController opens.
*/
func sideNavigationViewWillOpen(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition) {
print("Will open", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired after the
SideNavigationViewController opened.
*/
func sideNavigationViewDidOpen(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition) {
print("Did open", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired before the
SideNavigationViewController closes.
*/
func sideNavigationViewWillClose(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition) {
print("Will close", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired after the
SideNavigationViewController closed.
*/
func sideNavigationViewDidClose(sideNavigationViewController: SideNavigationViewController, position: SideNavigationPosition) {
print("Did close", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired when the
SideNavigationViewController pan gesture begins.
*/
func sideNavigationViewPanDidBegin(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition) {
print("Pan did begin for", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired when the
SideNavigationViewController pan gesture changes position.
*/
func sideNavigationViewPanDidChange(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition) {
print("Pan did change for", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired when the
SideNavigationViewController pan gesture ends.
*/
func sideNavigationViewPanDidEnd(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition) {
print("Pan did end for", .Left == position ? "Left" : "Right", "view.")
}
/**
An optional delegation method that is fired when the
SideNavigationViewController tap gesture begins.
*/
func sideNavigationViewDidTap(sideNavigationViewController: SideNavigationViewController, point: CGPoint, position: SideNavigationPosition) {
print("Did Tap for", .Left == position ? "Left" : "Right", "view.")
}
}
......@@ -740,16 +740,20 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
passed to the handler when recognized.
*/
internal func handleTapGesture(recognizer: UITapGestureRecognizer) {
if let v: MaterialView = leftView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Left)
if enabledLeftView && openedLeftView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeLeftView()
if openedLeftView {
if let v: MaterialView = leftView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Left)
if enabledLeftView && openedLeftView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeLeftView()
}
}
}
if let v: MaterialView = rightView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Right)
if enabledRightView && openedRightView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeRightView()
if openedRightView {
if let v: MaterialView = rightView {
delegate?.sideNavigationViewDidTap?(self, point: recognizer.locationInView(view), position: .Right)
if enabledRightView && openedRightView && !isPointContainedWithinView(v, point: recognizer.locationInView(v)) {
closeRightView()
}
}
}
}
......
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