-5

How can i create a searchbar like safari

Just like the photos I posted That the searchbar becomes small or hidden when the screen is scrolled

...

PHOTOS

mohammad
  • 1
  • 2

1 Answers1

0

It would be great if you could tell, what you've tried before. That way we can help you better.

In order to do that, you need a view of type UIScrollView (UITableView, UICollectionView, etc.).

Implement this delegate method and it should do the trick. Adjust the swipeThreshold variable to fit your needs.

   func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let swipeThreshold: CGFloat = 10
        let y = scrollView.panGestureRecognizer.translation(in: scrollView).y
        if y != 0 && swipeThreshold > y {
            navigationController?.setNavigationBarHidden(true, animated: true)
        } else {
            navigationController?.setNavigationBarHidden(false, animated: true)
        }
    }

Old answer as reference:

Here is one way to do it — by using SFSafariViewController using SafariServices.

import UIKit
import SafariServices

class MainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    // Call this method when you want to show the browser
    func doSomething() {
        let url = URL(string: "https://www.google.com")!
        let safariViewController = SFSafariViewController(url: url)
        present(safariViewController, animated: true, completion: nil)
    }
}
Devran Cosmo Uenal
  • 6,055
  • 2
  • 26
  • 29
  • no i dont need browser friend. i want to create a searchbar like safari app – mohammad Oct 05 '19 at 06:25
  • I've updated my answer. but honestly it would be good if you could update your question to be more detailed in what you actually are looking for and what you've tried so far. Other people with a similar question can find this page that way. – Devran Cosmo Uenal Oct 05 '19 at 07:24