ios - 在 UITabBarController 中使用 UINavigationController 时,UISearchBar 被截断

标签 ios swift uisearchbar uisearchcontroller

我正在尝试在我的 UITabBarController 中的一个选项卡中实现一个搜索栏,该选项卡是 UINavigationController 中的一个 UITableViewController ...我正在关注 Apple 教程 - 我尝试了很多不同的选项,包括此处提到的答案

Search bar gets cut off when using UISearchController with a UITabBarController inside a UINavigationController

我尝试使用以下属性设置

self.definesPresentationContext = true

self.tabBarController?.definesPresentationContext = true

这是我的代码(来自包含 UISearchBar 的 UITableViewController):

/// Search controller to help us with filtering.
    var searchController: UISearchController!

/// Secondary search results table view.
    var resultsTableController: SearchResultsTableController!

override func viewDidLoad() {
    super.viewDidLoad()
    resultsTableController = SearchResultsTableController()
    resultsTableController.tableView.delegate = self

    searchController = UISearchController(searchResultsController: resultsTableController)
    searchController.searchResultsUpdater = self
    searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar

    searchController.delegate = self
    searchController.dimsBackgroundDuringPresentation = true
    searchController.searchBar.delegate = self  // so we can monitor text changes

    self.definesPresentationContext = true
}

这是搜索栏的图片:

enter image description here

一旦我点击它: enter image description here

最佳答案

好的,问题终于解决了。这条线让它工作

self.extendedLayoutIncludesOpaqueBars = true 

我的 TabBar 不是半透明的,所以我认为这不会有什么不同,但我在我的 UITableviewcontroller(显示 UISearchController 的 Controller )上设置了它,现在导航栏中的搜索显示正确。我还将顶部和底部栏下的延伸边缘设置为 true(使用 Interface Builder)

关于ios - 在 UITabBarController 中使用 UINavigationController 时,UISearchBar 被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34170729/

相关文章:

ios - iOS在显示default.png时如何点按屏幕以继续

ios - 无法识别 UITableViewCell 中的 UITapGestureRecognizer

ios - 如果用户在游戏开始时关闭登录屏幕,稍后显示 GameCenter 登录?

swift - [UIActivityIndi​​catorView发布] : message sent to deallocated instance in swift-3

ios - UITextView如何实现搜索功能?

ios - 使 UISearchBar 背景清晰

iphone - UISearchBar 在 iOS 4.1 上删除背景

ios - 将两个CAF文件连接在一起

swift - 在这种情况下,我无法推断出什么类型?

IOS: ScrollView 中的声音