0

我用一個用UISearchController以編程方式創建的navBar。
當我開始編輯的UISearchBar:

- 導航欄停留在悲觀的看法
背後 - 的的tableView隱藏導航欄
的一半 - 當tabeView出現,取消按鈕是不可選擇的。


帶上UISearchController前的導航欄,Swift


我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 


我的導航欄:

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

我怎樣才能解決這個問題,好嗎?
謝謝!

+0

顯示更多的代碼,你創建它們會很好 – Tj3n

+0

@ Tj3n我更新了我的文章! ;) –

回答

0

你可以使用stackview。選擇搜索和tableview中,點擊來自stackview和約束stackview頂部/左/右/底部

enter image description here

+0

我更新了我的帖子;) –

+0

好的。您可以創建stackview對象,而是將newNavBar添加到stackview和locationSearchTable中。 –

1

嘗試使用這樣的:?

self.navigationController .navigationBar.layer.zPosition = 1