'hideUISearchBarWhenScrolling'-Property no

2019-07-29 05:46发布

I played around with the new Swift4/iOS11 possibilities and stuck with the problem that hideSearchBarWhenScrolling isn't working with a tableView as a property in UIViewController.

In UITableViewController it's working like it should work.

What am I doing wrong? Somebody issued the same problem an has an solution for this?

class AddController: UIViewController {

    let tableView: UITableView = {
        let tv = UITableView()
        tv.translatesAutoresizingMaskIntoConstraints = false
        return tv
    }()
    let searchController = UISearchController(searchResultsController: nil)

    override func viewDidLoad() {
        navigationItem.title = "Heading"
        navigationItem.searchController = searchController
        navigationController?.navigationBar.prefersLargeTitles = true
    }

    override func viewWillLayoutSubviews() {
        view.addSubview(tableView)

        NSLayoutConstraint.activate([
            tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
            tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
            tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
        ])
    }
}

Thanks

1条回答
倾城 Initia
2楼-- · 2019-07-29 06:16

Use like this :

navigationItem.hidesSearchBarWhenScrolling
查看更多
登录 后发表回答