因此,我的搜索栏看起来像这样,它是通过UISearchController调用的。除了一件事,一切都很好。
swift - 半透明的状态栏与UITableView内容重叠-LMLPHP

向下滚动搜索列表将在状态栏下显示结果,因为它是透明的,就像这样

swift - 半透明的状态栏与UITableView内容重叠-LMLPHP

我使用了几个“难看的”修复程序来使它看起来和正常运行,问题显然出在translucent = true-参数之内。谁能看到我的问题的快速解决方案?除了jsut以外,将另一个空的,非透明的视图放在顶部,并使其变为白色ofc。今天早些时候我遇到了另一个问题,而this问题的解决方案就是这种情况发生的原因。

func willPresentSearchController(searchController: UISearchController) {

    if let navBarFont = UIFont(name: "HelveticaNeue-Light", size: 25.0) {
        let navBarAttributesDictionary: [String: AnyObject]? = [
            NSForegroundColorAttributeName: PinkColor,
            NSFontAttributeName: navBarFont
        ]
        self.navigationController?.navigationBar.titleTextAttributes = navBarAttributesDictionary
    }

    self.navigationController?.navigationBar.translucent = true
    self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
    self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
    searchController.searchBar.backgroundColor = UIColor.whiteColor()
    self.navigationController?.navigationBar.topItem?.title = "Find Friends"
    self.refreshControl?.backgroundColor = UIColor.whiteColor()
    self.refreshControl?.tintColor = self.GrayColor
}
func willDismissSearchController(searchController: UISearchController) {

    if let navBarFont = UIFont(name: "HelveticaNeue-Light", size: 25.0) {
        let navBarAttributesDictionary: [String: AnyObject]? = [
            NSForegroundColorAttributeName: UIColor.whiteColor(),
            NSFontAttributeName: navBarFont
        ]
        self.navigationController?.navigationBar.titleTextAttributes = navBarAttributesDictionary
    }

    UIView.animateWithDuration(0.3) { () -> Void in
        self.navigationController?.navigationBar.translucent = false
        self.navigationController?.navigationBar.backgroundColor = self.PinkColor
        self.navigationController?.navigationBar.barTintColor = self.PinkColor
        searchController.searchBar.backgroundColor = self.PinkColor
        self.refreshControl?.backgroundColor = self.PinkColor
        self.refreshControl?.tintColor = UIColor.whiteColor()
        self.navigationController?.navigationBar.topItem?.title = "Friends"
    }
}

最佳答案

尝试这个:

self.edgesForExtendedLayout = UIRectEdgeNone;

08-18 15:49