加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – iOS11如何通过滚动同步大型导航栏崩溃

发布时间:2020-12-14 04:56:29 所属栏目:百科 来源:网络整理
导读:使用 Swift 3和Xcode 9我正在使用大型UINavigationBar视图: if #available(iOS 11.0,*) { navigationBar?.prefersLargeTitles = true UINavigationBar.appearance().largeTitleTextAttributes = [ NSForegroundColorAttributeName: Colors.black ]} 滚动UIT
使用 Swift 3和Xcode 9我正在使用大型UINavigationBar视图:

if #available(iOS 11.0,*) {

    navigationBar?.prefersLargeTitles = true

    UINavigationBar.appearance().largeTitleTextAttributes = [
        NSForegroundColorAttributeName: Colors.black
    ]

}

滚动UITableView时,条形图会快速折叠,从而产生不需要的空间:

之前:

enter image description here

后:

enter image description here

当我触摸UITableView时,条形图会折叠.

tableView具有以下属性:

let rect = CGRect(

    x: 0,y: UIApplication.shared.statusBarView?.frame.height ?? 20,width: UIScreen.main.bounds.width,height: UIScreen.main.bounds.height

)

let tableView = UITableView(frame: rect)

tableView的顶部插图是self.navigationController?.navigationBar.frame.height ?? 44

tableView也设置为:

if #available(iOS 11.0,*) {
    self.contentInsetAdjustmentBehavior = .never
}

酒吧是半透明的,我希望保持这一点.我错过了什么?非常感谢帮助.

解决方法

我不知道它对你有用.但它的示例代码对我有用.

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UISearchResultsUpdating {
    var numbers: [String] = []

    let rect = CGRect(
        x: 0,y: UIApplication.shared.statusBarFrame.height ?? 20,height: UIScreen.main.bounds.height
    )

    lazy var tableView: UITableView = {
        let tV = UITableView()
        tV.delegate = self
        tV.dataSource = self
        tV.register(UITableViewCell.classForCoder(),forCellReuseIdentifier: "cell")
        return tV
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        numbers = generateNumbers()
        self.view.backgroundColor = UIColor.white
        title = "Numbers"

        self.navigationController?.navigationBar.prefersLargeTitles = true

        let search = UISearchController(searchResultsController: nil)
        search.hidesNavigationBarDuringPresentation = false
        search.searchResultsUpdater = self
        search.definesPresentationContext = true
        self.navigationItem.searchController = search
        tableView.frame = rect

        self.view.addSubview(tableView)
    }

    func generateNumbers() -> [String] {
        var numbers = [String]()
        for var i in 1..<100 {
            numbers.append(String(i))
        }
        return numbers
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        return numbers.count
    }

    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
        cell.textLabel?.text = self.numbers[indexPath.row]
        return cell
    }

    func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath,animated: true)
    }

    func updateSearchResults(for searchController: UISearchController) {
        if let text = searchController.searchBar.text,!text.isEmpty {
            numbers = self.numbers.filter({ (number) -> Bool in
                return number.contains(text)
            })
        } else {
            numbers = generateNumbers()
        }
        self.table.reloadData()
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读