iOS13中的SearchController

问题描述 投票:0回答:1

我正在将actionController添加到navigationItem中。在iOS12中,它可以正常显示,但在iOS 13中,则没有显示。在调试视图层次结构上,它显示已添加搜索栏,但其高度已设置为零。无法找到正确的解决方案。

Code:

func setupSearchController() {

    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self as UISearchResultsUpdating
    searchController.searchBar.placeholder = "Search here..."
    searchController.searchBar.delegate = self as UISearchBarDelegate
    searchController.searchBar.tintColor = .white
    searchController.searchBar.barTintColor = .white
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.showsCancelButton = true 

    if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {

        textfield.textColor = UIColor.blue

        if let backgroundview = textfield.subviews.first {

            // Background color
            backgroundview.backgroundColor = UIColor.white

            // Rounded corner
            backgroundview.layer.cornerRadius = 10;
            backgroundview.clipsToBounds = true;
        }
    }

    if #available(iOS 11.0, *) {
        self.navigationItem.searchController = searchController
    } else {
        self.tblView.tableHeaderView = searchController.searchBar
    }
}

在Debug Navigator中,

enter image description here

在尺寸检查器中,

enter image description here

ios swift uisearchcontroller ios13
1个回答
0
投票

尝试设置搜索栏的框架

searchController. searchBar.frame = CGRect(x: 0, y: 0, width:view.frame.size.width, height: 50)
© www.soinside.com 2019 - 2024. All rights reserved.