From b34fd416502d70b3bbc1f6cd66ae3a9133761cb0 Mon Sep 17 00:00:00 2001 From: Shin Yamamoto Date: Sat, 5 Dec 2020 11:36:54 +0900 Subject: [PATCH] Fix Maps samlpe (#411) * Fix the detail vc layout in Maps sample * Deactivate search bar when the detail vc shows in Maps sample --- Examples/Maps/Maps/Base.lproj/Main.storyboard | 12 ++++++------ Examples/Maps/Maps/SearchViewController.swift | 3 +++ Examples/Maps/Maps/ViewController.swift | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Examples/Maps/Maps/Base.lproj/Main.storyboard b/Examples/Maps/Maps/Base.lproj/Main.storyboard index 9d89dd3b..68fac7f0 100644 --- a/Examples/Maps/Maps/Base.lproj/Main.storyboard +++ b/Examples/Maps/Maps/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -28,6 +28,7 @@ + @@ -39,7 +40,6 @@ - @@ -233,6 +233,7 @@ + @@ -240,7 +241,6 @@ - @@ -262,7 +262,7 @@ - + @@ -282,8 +282,8 @@ - + diff --git a/Examples/Maps/Maps/SearchViewController.swift b/Examples/Maps/Maps/SearchViewController.swift index 51f5ed9f..f54dec22 100644 --- a/Examples/Maps/Maps/SearchViewController.swift +++ b/Examples/Maps/Maps/SearchViewController.swift @@ -21,6 +21,9 @@ extension ViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) + + deactivate(searchBar: searchVC.searchBar) + // Show a detail panel switch indexPath.row { case 0: diff --git a/Examples/Maps/Maps/ViewController.swift b/Examples/Maps/Maps/ViewController.swift index ea724b88..428e0fa7 100644 --- a/Examples/Maps/Maps/ViewController.swift +++ b/Examples/Maps/Maps/ViewController.swift @@ -114,19 +114,27 @@ extension FloatingPanelController { // MARK: - UISearchBarDelegate extension ViewController: UISearchBarDelegate { - func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { + func activate(searchBar: UISearchBar) { + searchBar.showsCancelButton = true + searchVC.showHeader(animated: true) + searchVC.tableView.alpha = 1.0 + detailVC.dismiss(animated: true, completion: nil) + } + func deactivate(searchBar: UISearchBar) { searchBar.resignFirstResponder() searchBar.showsCancelButton = false searchVC.hideHeader(animated: true) + } + + func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { + deactivate(searchBar: searchBar) UIView.animate(withDuration: 0.25) { self.fpc.move(to: .half, animated: false) } } func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { - searchBar.showsCancelButton = true - searchVC.showHeader(animated: true) - searchVC.tableView.alpha = 1.0 + activate(searchBar: searchBar) UIView.animate(withDuration: 0.25) { [weak self] in self?.fpc.move(to: .full, animated: false) }