ios - 当导航栏半透明 = false 时 UISearchBar 超出屏幕边界

标签 ios iphone swift ios8

我尝试将 UISearchBarController 添加到 tableView,但是当我设置 UINavigationBar.appearance().translucent = false 然后 UISearchBar 隐藏在屏幕之外

在 TableViewController 中

var resultSearchC: UISearchController = UISearchController()

override func viewDidLoad() {
    super.viewDidLoad()

    self.resultSearchC = ({
        let c = UISearchController(searchResultsController: nil)
        c.searchResultsUpdater = self

        c.searchBar.translucent = true

        c.searchBar.barTintColor =  .redColor()
        c.searchBar.sizeToFit()

        self.tableView.tableHeaderView = c.searchBar

        return c
    })()

    // self.edgesForExtendedLayout = .None

    self.tableView.reloadData()
}

应用委托(delegate):

let navBarAppearance = UINavigationBar.appearance()

    navBarAppearance.barStyle = .Black
    navBarAppearance.translucent = false

最佳答案

您需要在 viewDidLoad() 中将 extendedLayoutIncludesOpaqueBars 设置为 true。

extendedLayoutIncludesOpaqueBars = true;

关于ios - 当导航栏半透明 = false 时 UISearchBar 超出屏幕边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29453228/

相关文章:

ios - 覆盖核心数据值

ios - 如何允许选择和取消选择多个 UICollectionViewCell?

android - google play store 和 apple app store 是否仍然支持 ionic v1 应用程序?

iphone - 有没有一种方法可以使用`someButton.enabled = NO;`而不会使自定义图像UIButton变暗?

swift - 在 iOS 中将图像转换为视频而不锁定 UI 线程 (Swift)

ios - 在 ARKit 中使用物理时,是什么导致 SCNNode 不相互接触?

javascript - 在 chrome IOS 选项卡上打开 base64 pdf

iphone - NSURLRequest 超时 IOS

iphone - 新手: UINavigationController is pulling me back from further learning :(

iphone - 使用 NSRegularExpression 提取文本