diff --git a/Example/DisplaySwitcher/Base.lproj/Main.storyboard b/Example/DisplaySwitcher/Base.lproj/Main.storyboard index dd5dddf..56afca6 100644 --- a/Example/DisplaySwitcher/Base.lproj/Main.storyboard +++ b/Example/DisplaySwitcher/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -82,12 +82,9 @@ - - - - + @@ -132,12 +129,6 @@ - - - - - - diff --git a/Example/DisplaySwitcher/ViewControllers/UserViewController/UserViewController.swift b/Example/DisplaySwitcher/ViewControllers/UserViewController/UserViewController.swift index 134fc9d..1ce65ac 100644 --- a/Example/DisplaySwitcher/ViewControllers/UserViewController/UserViewController.swift +++ b/Example/DisplaySwitcher/ViewControllers/UserViewController/UserViewController.swift @@ -20,6 +20,7 @@ class UserViewController: UIViewController { @IBOutlet private weak var searchBar: UISearchBar! @IBOutlet private weak var rotationButton: RotationButton! + private var tap: UITapGestureRecognizer! private var users = UserDataProvider().generateFakeUsers() private var searchUsers = [User]() private var isTransitionAvailable = true @@ -31,10 +32,11 @@ class UserViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + tap = UITapGestureRecognizer(target: self, action: #selector(handleTap)) + searchUsers = users rotationButton.selected = true setupCollectionView() - addGestureRecognizerToNavBar() } // MARK: - Private methods @@ -43,11 +45,6 @@ class UserViewController: UIViewController { collectionView.registerNib(UserCollectionViewCell.cellNib, forCellWithReuseIdentifier:UserCollectionViewCell.id) } - private func addGestureRecognizerToNavBar() { - let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(UserViewController.tapRecognized)) - navigationController!.navigationBar.addGestureRecognizer(tapRecognizer) - } - // MARK: - Actions @IBAction func buttonTapped(sender: AnyObject) { if !isTransitionAvailable { @@ -123,5 +120,20 @@ extension UserViewController { collectionView.reloadData() } + func collectionView(collectionView: UICollectionView,didSelectItemAtIndexPath indexPath: NSIndexPath) { + print("Hi \(indexPath.row)") + } + + func searchBarTextDidBeginEditing(searchBar: UISearchBar) { + view.addGestureRecognizer(tap) + } + + func searchBarTextDidEndEditing(searchBar: UISearchBar) { + view.removeGestureRecognizer(tap) + } + + func handleTap() { + view.endEditing(true) + } }