diff --git a/HidingNavigationBar/HidingNavigationBarManager.swift b/HidingNavigationBar/HidingNavigationBarManager.swift index bcb1e02..b1fde29 100644 --- a/HidingNavigationBar/HidingNavigationBarManager.swift +++ b/HidingNavigationBar/HidingNavigationBarManager.swift @@ -75,10 +75,8 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture // Hiding navigation bar state fileprivate var currentState = HidingNavigationBarState.Open fileprivate var previousState = HidingNavigationBarState.Open - - //Gesture fileprivate var panGesture: UIPanGestureRecognizer? - + //Options open var onForegroundAction = HidingNavigationForegroundAction.default @@ -162,6 +160,7 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture } open func viewWillAppear(_ animated: Bool) { + panGesture?.isEnabled = true expand() } @@ -171,6 +170,7 @@ open class HidingNavigationBarManager: NSObject, UIScrollViewDelegate, UIGesture open func viewWillDisappear(_ animated: Bool) { expand() + panGesture?.isEnabled = false } open func updateValues() { diff --git a/HidingNavigationBarSample/HidingNavigationBarSample.xcodeproj/project.pbxproj b/HidingNavigationBarSample/HidingNavigationBarSample.xcodeproj/project.pbxproj index 36222d8..b640921 100644 --- a/HidingNavigationBarSample/HidingNavigationBarSample.xcodeproj/project.pbxproj +++ b/HidingNavigationBarSample/HidingNavigationBarSample.xcodeproj/project.pbxproj @@ -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, ); }; }; @@ -58,6 +61,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 52258B371E6412EA007E9A19 /* HiddenNavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HiddenNavViewController.swift; sourceTree = ""; }; + 52258B391E6413F2007E9A19 /* HidingNavShowsNavViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HidingNavShowsNavViewController.swift; sourceTree = ""; }; + 52258B421E66E55A007E9A19 /* InteractivePopGestureRecognizerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractivePopGestureRecognizerDelegate.swift; sourceTree = ""; }; 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 = ""; }; 6A412A2F1BB1CBA4001C3F67 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -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 */, @@ -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 */, diff --git a/HidingNavigationBarSample/HidingNavigationBarSample/HiddenNavViewController.swift b/HidingNavigationBarSample/HidingNavigationBarSample/HiddenNavViewController.swift new file mode 100644 index 0000000..c32261b --- /dev/null +++ b/HidingNavigationBarSample/HidingNavigationBarSample/HiddenNavViewController.swift @@ -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 + } + +} diff --git a/HidingNavigationBarSample/HidingNavigationBarSample/HidingNavShowsNavViewController.swift b/HidingNavigationBarSample/HidingNavigationBarSample/HidingNavShowsNavViewController.swift new file mode 100644 index 0000000..98bffab --- /dev/null +++ b/HidingNavigationBarSample/HidingNavigationBarSample/HidingNavShowsNavViewController.swift @@ -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 + } + +} diff --git a/HidingNavigationBarSample/HidingNavigationBarSample/InteractivePopGestureRecognizerDelegate.swift b/HidingNavigationBarSample/HidingNavigationBarSample/InteractivePopGestureRecognizerDelegate.swift new file mode 100644 index 0000000..1955c75 --- /dev/null +++ b/HidingNavigationBarSample/HidingNavigationBarSample/InteractivePopGestureRecognizerDelegate.swift @@ -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 { + +} diff --git a/HidingNavigationBarSample/HidingNavigationBarSample/MasterViewController.swift b/HidingNavigationBarSample/HidingNavigationBarSample/MasterViewController.swift index 78d0b1e..7b496dd 100644 --- a/HidingNavigationBarSample/HidingNavigationBarSample/MasterViewController.swift +++ b/HidingNavigationBarSample/HidingNavigationBarSample/MasterViewController.swift @@ -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() @@ -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) @@ -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) } - } }