如何在iOS 11中关闭通过UITableView调整大标题的功能? [英] How to turn off adjusting large titles by UITableView in iOS 11?

查看:82
本文介绍了如何在iOS 11中关闭通过UITableView调整大标题的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 11中有一个大标题功能,当 UITableViewController 的表滚动到顶部时显示大标题,而当用户从顶部滚动表时将其折叠为标准小标题.这是标准行为.我需要导航控制器的行为有所不同-我需要始终显示大标题.如何实现呢?

There's this large titles feature in iOS 11 that shows large title when the UITableViewController's table is scrolled to top, and gets collapsed to standard small title when the user scrolls the table away from top. This is standard behavior. I need the navigation controller to behave a bit differently - I need to always show the large title. How to achieve this?

下面的代码无济于事,滚动时它仍然崩溃.

Following code does not help, it still collapses when scrolled.

navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always

推荐答案

当将 UITableViewController 嵌入到 UIViewController 内时,我无意中实现了它.

I've achieved it unintentionally when embedded UITableViewController inside UIViewController.

我不确定这是苹果的错误还是预期的行为.

I'm not sure whether it is an Apple's bug or intended behavior.

所以堆栈就像 UINavigationController -> UIViewController (用作容器)-> UITableViewController

So stack is as simple as UINavigationController -> UIViewController(used as container) -> UITableViewController

这是带有嵌入式 UITableViewController 全屏显示的视图控制器的示例

Here is sample of view controller with embedded UITableViewController fullscreen

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var vc = UITableViewController(style: .plain)
    var array: [String] = []

    override func viewDidLoad() {
        super.viewDidLoad()

        vc.view.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(vc.view)
        view.addConstraint(view.leadingAnchor.constraint(equalTo: vc.view.leadingAnchor))
        view.addConstraint(view.rightAnchor.constraint(equalTo: vc.view.rightAnchor))
        view.addConstraint(view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: vc.view.topAnchor))
        view.addConstraint(view.bottomAnchor.constraint(equalTo: vc.view.bottomAnchor))

        vc.tableView.delegate = self
        vc.tableView.dataSource = self

        array = "0123456789".characters.map(String.init)
        vc.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "identifier")

        title = "Title"
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath)
        cell.textLabel?.text = array[indexPath.row]
        return cell
    }
}

这是结果

Here is the result

希望有帮助.

P.S.令人惊讶的是,我目前的问题是我不知道如何在这种架构下崩溃:)

P.S. Surprisingly, my current problem is that I don't know how to get collapsing behavior with such architecture :)

这篇关于如何在iOS 11中关闭通过UITableView调整大标题的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆