UISearchController的UISearchBar突然更改self和Parent VC的位置

时间:2018-12-08 08:55:08

标签: ios swift uiviewcontroller uisearchbar uisearchcontroller

我对UISearchBar有疑问。当我只使用UISearchBar时,它可以很好地工作。但我想使用Cancel按钮和其他UISearchController的功能。 不幸的是,我的SearchViewController必须在弹出窗口中显示(我正在使用Presentr CocoaPod)。 仅当我单击UISearchBar时才会出现问题。

不关注UISearchBarenter image description here

具有焦点和切换的键盘(屏幕的同一片段): enter image description here

它只是简单地向左移动。由于Presenter的弹出框,因此已被剪掉。

这是代码:

class SearchViewController: UIViewController {
    private let tableView = UITableView()
    private let searchController = UISearchController(searchResultsController: nil)
    private let doneButton = UIButton(type: .system)
    private var data: [String]?

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        tableView.delegate = self
        searchController.delegate = self
        searchController.searchBar.delegate = self
        searchController.searchResultsUpdater = self
        setupViews()
    }
    init(data: [String]) {
        self.data = data
        super.init(nibName: nil, bundle: nil)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupViews() {
        view.addSubview(searchController.searchBar)
        searchController.searchBar.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
        }
        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.top.equalTo(searchController.searchBar.snp.bottom)
            make.bottom.right.left.equalToSuperview()
        }
        extendedLayoutIncludesOpaqueBars = true
        searchController.dimsBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "Search your country code"
        tableView.tableFooterView = doneButton
        definesPresentationContext = true
        automaticallyAdjustsScrollViewInsets = false
    }
}

请忘记doneButton,它尚未使用。

0 个答案:

没有答案