-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from asaake/use-interactivePopGestureRecognizer
Use interactivePopGestureRecognizer.delegate and edge swipe.
- Loading branch information
Showing
6 changed files
with
203 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
HidingNavigationBarSample/HidingNavigationBarSample/HiddenNavViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
HidingNavigationBarSample/HidingNavigationBarSample/HidingNavShowsNavViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...vigationBarSample/HidingNavigationBarSample/InteractivePopGestureRecognizerDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters