Swift   发布时间:2022-04-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift – iOS11如何通过滚动同步大型导航栏崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用 Swift 3和Xcode 9我正在使用大型UINavigationBar视图:

if #available(iOS 11.0,*) {

    navigationBar?.prefersLargetitles = true

    UINavigationBar.appearance().largetitleTextAttributes = [
        NSForegroundColorAttributename: Colors.black
    ]

}

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

之前:

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

后:

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

当我触摸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()
    }
}

大佬总结

以上是大佬教程为你收集整理的swift – iOS11如何通过滚动同步大型导航栏崩溃全部内容,希望文章能够帮你解决swift – iOS11如何通过滚动同步大型导航栏崩溃所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。