0

I used a navBar which is created programmatically with an UISearchController.
When I start editing the UISearchBar:

- the navBar stays behind the dim view
- the tableView hides half of the navbar
- when the tabeView appeared, the cancel buttons are not selectable.



My UISearchController :

   let locationSearchTable = storyboard!.instantiateViewControllerWithIdentifier("SearchTableViewController") as!  SearchTableViewController
    resultSearchController = UISearchController(searchResultsController: locationSearchTable)
    resultSearchController.searchResultsUpdater = locationSearchTable
    resultSearchController.view.backgroundColor=UIColor.clearColor()
    locationSearchTable.delegate = self

    let searchBar = self.resultSearchController.searchBar
    searchBar.sizeToFit()
    searchBar.placeholder = "Search"
    searchBar.searchBarStyle = .Minimal
    searchBar.barStyle = .Default
    searchBar.translucent = true
    searchBar.barTintColor = UIColor.whiteColor()
    searchBar.setImage(UIImage(named:"search"), forSearchBarIcon: .Search, state : .Normal)
    searchBar.delegate=self
    resultSearchController.hidesNavigationBarDuringPresentation = false
    resultSearchController.dimsBackgroundDuringPresentation = true
    definesPresentationContext = true


My navBar :

let newNavBar : UINavigationBar = UINavigationBar.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64.0))

func styleNavBar (){

    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default
    self.navigationController?.setNavigationBarHidden(true, animated: false)


    let newItem : UINavigationItem = UINavigationItem.init()
    newItem.titleView = self.resultSearchController.searchBar

    newNavBar.barTintColor = UIColor(red: 243/255, green: 242/255, blue: 238/255, alpha: 1.0)
        newNavBar.translucent = false
        if let font = UIFont(name: "Avenir-Black", size: 16.0) {
            let navBarAttributesDictionary : [String : AnyObject]? = [
                NSForegroundColorAttributeName: UIColor(red: 74/255, green: 74/255, blue: 74/255, alpha: 0.51),
                NSFontAttributeName: font
            ]
            newNavBar.titleTextAttributes = navBarAttributesDictionary
        }

    newNavBar.setItems([newItem], animated: false)

    self.view.addSubview(newNavBar)
    self.view.bringSubviewToFront(newNavBar)
}

enter image description here

How can I fix it, please?
Thanks!

2
  • show more code where you created them would be good Commented Aug 24, 2016 at 3:58
  • @Tj3n I updated my post! ;) Commented Aug 24, 2016 at 7:12

2 Answers 2

1

Try using this :

self.navigationController?.navigationBar.layer.zPosition = 1

Sign up to request clarification or add additional context in comments.

Comments

0

you can use stackview for it . select search and tableview and click on stackview and constraint stackview from top/left/right/bottom

enter image description here

1 Comment

ok . you can create stackview object and instead add newNavBar into stackview and locationSearchTable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.