0

I have added search bar in navigation bar large title. I am facing a flicker issue when the search bar is tapped to type into it.

Here is the video to the explain the issue:

enter image description here

The code I have written to achieve this is:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        self.title = "Leads"
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addNewLeadsAction(_:)))
        let mysearchController = UISearchController(searchResultsController: nil)
        mysearchController.searchResultsUpdater = self
        mysearchController.searchBar.placeholder = "Search Lead"
        mysearchController.searchBar.showsCancelButton = true
        mysearchController.searchBar.barStyle = UIBarStyle.default
        mysearchController.searchBar.backgroundColor = UIColor(patternImage: Common.gradientImage(view: (self.navigationController?.navigationBar)!))
        if let textfield = mysearchController.searchBar.value(forKey: "searchField") as? UITextField {
            textfield.textColor = UIColor.white
            if let backgroundview = textfield.subviews.first {
                backgroundview.backgroundColor = .white
                backgroundview.layer.cornerRadius = 10
                backgroundview.clipsToBounds = true
            }
        }
        for searchBarView in mysearchController.searchBar.subviews{
            for cancelButtonView in searchBarView.subviews{
                if cancelButtonView.isKind(of: UIButton.self) {
                    let filterButton:UIButton = cancelButtonView as! UIButton
                    filterButton.isEnabled = true
                    filterButton.setTitle("", for: .normal)
                    let image1 = UIImage(named: "filterIcon")?.withRenderingMode(.alwaysTemplate)
                    filterButton.setImage(image1, for: .normal)
                    filterButton.contentMode = .scaleAspectFit
                    filterButton.tintColor = .white
                    filterButton.addTarget(self, action: #selector(filterAction(_:)), for: .touchUpInside)
                }
            }
        }
        self.navigationItem.searchController = mysearchController
        self.definesPresentationContext = true
        leadsTableView.reloadData()
    }

Trying to make the transition smooth is what i'm looking to achieve. Following are the things I have tried already:

iOS 11 UISearchBar in UINavigationBar

Navigation bar + Search controller + Large title: Hairline during scrolling

Any help will be appreciated

Mamta
  • 921
  • 1
  • 10
  • 28

0 Answers0