Skip to content

Commit

Permalink
Added trackingPanGestureRecognizer to use interactivePopGestureRecogn…
Browse files Browse the repository at this point in the history
…izer.delegate
  • Loading branch information
asaake committed Mar 3, 2017
1 parent 4e4aa98 commit 0aae95c
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 4 deletions.
7 changes: 6 additions & 1 deletion HidingNavigationBar/HidingNavigationBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture
// Hiding navigation bar state
fileprivate var currentState = HidingNavigationBarState.Open
fileprivate var previousState = HidingNavigationBarState.Open


fileprivate var trackingScrollViewPanGestureRecognizer: UIPanGestureRecognizer!

//Options
open var onForegroundAction = HidingNavigationForegroundAction.default

Expand Down Expand Up @@ -87,6 +89,7 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(HidingNavigationBarManager.handlePanGesture(_:)))
panGesture.delegate = self
scrollView.addGestureRecognizer(panGesture)
trackingScrollViewPanGestureRecognizer = panGesture

navBarController.expandedCenter = {[weak self] (view: UIView) -> CGPoint in
return CGPoint(x: view.bounds.midX, y: view.bounds.midY + (self?.statusBarHeight() ?? 0))
Expand Down Expand Up @@ -138,6 +141,7 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture
}

open func viewWillAppear(_ animated: Bool) {
trackingScrollViewPanGestureRecognizer.isEnabled = true
expand()
}

Expand All @@ -147,6 +151,7 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture

open func viewWillDisappear(_ animated: Bool) {
expand()
trackingScrollViewPanGestureRecognizer.isEnabled = false
}

open func updateValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
52258B381E6412EA007E9A19 /* HiddenNavViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52258B371E6412EA007E9A19 /* HiddenNavViewController.swift */; };
52258B3A1E6413F2007E9A19 /* HidingNavShowsNavViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52258B391E6413F2007E9A19 /* HidingNavShowsNavViewController.swift */; };
52258B431E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52258B421E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift */; };
6A412A2E1BB1CBA4001C3F67 /* HidingNavigationBar.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A412A2D1BB1CBA4001C3F67 /* HidingNavigationBar.h */; settings = {ATTRIBUTES = (Public, ); }; };
6A412A401BB1CBA4001C3F67 /* HidingNavigationBar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A412A2B1BB1CBA4001C3F67 /* HidingNavigationBar.framework */; };
6A412A411BB1CBA4001C3F67 /* HidingNavigationBar.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6A412A2B1BB1CBA4001C3F67 /* HidingNavigationBar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -58,6 +61,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
52258B371E6412EA007E9A19 /* HiddenNavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HiddenNavViewController.swift; sourceTree = "<group>"; };
52258B391E6413F2007E9A19 /* HidingNavShowsNavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HidingNavShowsNavViewController.swift; sourceTree = "<group>"; };
52258B421E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractivePopGestureRecognizerDelegate.swift; sourceTree = "<group>"; };
6A412A2B1BB1CBA4001C3F67 /* HidingNavigationBar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HidingNavigationBar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6A412A2D1BB1CBA4001C3F67 /* HidingNavigationBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HidingNavigationBar.h; sourceTree = "<group>"; };
6A412A2F1BB1CBA4001C3F67 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -156,6 +162,9 @@
6A65711D1AF3FDB600A6CFE4 /* HidingNavExtensionViewController.swift */,
6A6571231AF40E7000A6CFE4 /* HidingNavTabViewController.swift */,
6A65711F1AF408C000A6CFE4 /* HidingNavToolbarViewController.swift */,
52258B371E6412EA007E9A19 /* HiddenNavViewController.swift */,
52258B391E6413F2007E9A19 /* HidingNavShowsNavViewController.swift */,
52258B421E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift */,
6A6570F31AF3F71100A6CFE4 /* Main.storyboard */,
6A6570F61AF3F71100A6CFE4 /* Images.xcassets */,
6A6570F81AF3F71100A6CFE4 /* LaunchScreen.xib */,
Expand Down Expand Up @@ -355,11 +364,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
52258B381E6412EA007E9A19 /* HiddenNavViewController.swift in Sources */,
6A6571211AF408C000A6CFE4 /* HidingNavToolbarViewController.swift in Sources */,
6A65711B1AF3FADC00A6CFE4 /* HidingNavigationBarManager.swift in Sources */,
6A6571241AF40E7000A6CFE4 /* HidingNavTabViewController.swift in Sources */,
6A6570F01AF3F71100A6CFE4 /* MasterViewController.swift in Sources */,
6A6570EE1AF3F71100A6CFE4 /* AppDelegate.swift in Sources */,
52258B3A1E6413F2007E9A19 /* HidingNavShowsNavViewController.swift in Sources */,
52258B431E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift in Sources */,
6A6571121AF3F8D900A6CFE4 /* HidingNavViewController.swift in Sources */,
6A65711C1AF3FADC00A6CFE4 /* HidingViewController.swift in Sources */,
6A65711E1AF3FDB600A6CFE4 /* HidingNavExtensionViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// HiddenNavViewController.swift
// HidingNavigationBarSample
//
// Created by asaake on 2017/02/27.
// Copyright (c) 2017 Tristan Himmelman. All rights reserved.
//

import UIKit

class HiddenNavViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let identifier = "cell"
var tableView: UITableView!

override func viewDidLoad() {
super.viewDidLoad()

tableView = UITableView(frame: view.bounds)
tableView.dataSource = self
tableView.delegate = self
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: identifier)
view.addSubview(tableView)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

// MARK: UITableViewDelegate

func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
return true
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
dismiss(animated: true, completion: nil)
} else {
let controller = HidingNavShowsNavViewController()
navigationController?.pushViewController(controller, animated: true)
}
}

// MARK: - Table view data source

func numberOfSections(in tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 100
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)

// Configure the cell...
if indexPath.row == 0 {
cell.textLabel?.text = "close controller";
cell.selectionStyle = UITableViewCellSelectionStyle.none
} else {
cell.textLabel?.text = "row \((indexPath as NSIndexPath).row)"
cell.selectionStyle = UITableViewCellSelectionStyle.none
}
return cell
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// HidingNavShowsNavViewController.swift
// HidingNavigationBarSample
//
// Created by asaake on 2017/02/27.
// Copyright (c) 2017 Tristan Himmelman. All rights reserved.
//

import UIKit

class HidingNavShowsNavViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let identifier = "cell"
var hidingNavBarManager: HidingNavigationBarManager?
var tableView: UITableView!

override func viewDidLoad() {
super.viewDidLoad()

tableView = UITableView(frame: view.bounds)
tableView.dataSource = self
tableView.delegate = self
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: identifier)
view.addSubview(tableView)

let backButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(HidingNavShowsNavViewController.backButtonTouched))
navigationItem.leftBarButtonItem = backButton

hidingNavBarManager = HidingNavigationBarManager(viewController: self, scrollView: tableView)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
tableView.panGestureRecognizer.require(toFail: navigationController!.interactivePopGestureRecognizer!)
hidingNavBarManager?.viewWillAppear(animated)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
hidingNavBarManager?.viewDidLayoutSubviews()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
hidingNavBarManager?.viewWillDisappear(animated)
}

func backButtonTouched(){
_ = navigationController?.popViewController(animated: true)
}

// MARK: UITableViewDelegate

func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
hidingNavBarManager?.shouldScrollToTop()

return true
}

// MARK: - Table view data source

func numberOfSections(in tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 100
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)

// Configure the cell...
cell.textLabel?.text = "row \((indexPath as NSIndexPath).row)"
cell.selectionStyle = UITableViewCellSelectionStyle.none

return cell
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// InteractivePopGestureRecognizerDelegate.swift
// HidingNavigationBarSample
//
// Created by asaake on 2017/03/01.
// Copyright (c) 2017 Tristan Himmelman. All rights reserved.
//

import UIKit

class InteractivePopGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class MasterViewController: UITableViewController {

let rows = ["Hiding Nav Bar", "Hiding Nav Bar + Extension View", "Hiding Nav Bar + Toolbar", "Hiding Nav Bar + TabBar"]
let rows = ["Hiding Nav Bar", "Hiding Nav Bar + Extension View", "Hiding Nav Bar + Toolbar", "Hiding Nav Bar + TabBar", "Hidden Shows NavBar + InteractivePopGestureRecognizer"]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -65,7 +65,7 @@ class MasterViewController: UITableViewController {
} else if (indexPath as NSIndexPath).row == 2 {
let controller = HidingNavToolbarViewController()
navigationController?.pushViewController(controller, animated: true)
} else {
} else if (indexPath as NSIndexPath).row == 3 {
let controller1 = HidingNavTabViewController()
let navController1 = UINavigationController(rootViewController: controller1)
navController1.tabBarItem = UITabBarItem(tabBarSystemItem: .mostRecent, tag: 0)
Expand All @@ -78,8 +78,13 @@ class MasterViewController: UITableViewController {
let tabBarController = UITabBarController()
tabBarController.viewControllers = [navController1, navController2]
navigationController?.present(tabBarController, animated: true, completion: nil)
} else {
let controller = HiddenNavViewController()
let navController = UINavigationController(rootViewController: controller)
navController.interactivePopGestureRecognizer?.delegate = InteractivePopGestureRecognizerDelegate()
styleNavigationController(navController)
navigationController?.present(navController, animated: true, completion: nil)
}


}
}
Expand Down

0 comments on commit 0aae95c

Please sign in to comment.