4

我试图在 a 中显示一个大TitleNavigation bar,但背景清晰。向上滚动时,它将Navigation bar具有模糊效果。

在此处输入图像描述

在此处输入图像描述

这看起来是正确的,但是,在滚动时,动画似乎被破坏了。此外,过渡有时会卡住:

在此处输入图像描述

在此处输入图像描述

我的代码如下:

UINavigationController

override func viewDidLoad() {
   super.viewDidLoad()

   if #available(iOS 13.0, *) {

      self.navigationBar.prefersLargeTitles = true

      let style = UINavigationBarAppearance()
      style.configureWithDefaultBackground()

      style.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 18)]

      self.navigationBar.standardAppearance = style
      self.navigationBar.compactAppearance = style


      //Configure Large Style
      let largeStyle = UINavigationBarAppearance()
      largeStyle.configureWithTransparentBackground()

      largeStyle.largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 28)]

      self.navigationBar.scrollEdgeAppearance = largeStyle

   }
}

是在UITableView里面UINavigationController。两者都来自故事板,通过 segue 方式。

4

4 回答 4

5

代替 UITableview,您可以尝试使用 UITableViewController。我已经尝试使用 UITableViewController 并且它对我来说工作正常。请检查以下设计和代码。

在此处输入图像描述

class ViewController: UITableViewController
{
    override func viewDidLoad() {
        super.viewDidLoad()
          if #available(iOS 13.0, *) {
                  self.navigationController?.navigationBar.prefersLargeTitles = true
                  let style = UINavigationBarAppearance()
                  style.configureWithDefaultBackground()
                  style.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 18)]
                  self.navigationController?.navigationBar.standardAppearance = style
                  self.navigationController?.navigationBar.compactAppearance = style
                  //Configure Large Style
                  let largeStyle = UINavigationBarAppearance()
                  largeStyle.configureWithTransparentBackground()
                  largeStyle.largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 28)]
                  self.navigationController?.navigationBar.scrollEdgeAppearance = largeStyle
              }
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
        // Do any additional setup after loading the view.
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        1
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        10
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = "\(indexPath.row)"
        return cell
    }
}

输出:-

在此处输入图像描述

于 2019-11-27T09:26:56.507 回答
4

在视图调试器中,检查导航标题是否超出导航栏范围。如果是这样的话:

let titleHeight = UIFont.systemFont(ofSize: 28).lineHeight
if titleHeight > self.view.frame.size.height {
   self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, titleHeight + topAndBottomPadding)
}
于 2019-11-24T07:40:22.693 回答
4

嘿,你好吗是你的代码尝试删除这一行

    largeStyle.configureWithTransparentBackground()

你必须用白色背景配置

你的代码:

    override func viewDidLoad() {
    super.viewDidLoad()

    if #available(iOS 13.0, *) {

  self.navigationBar.prefersLargeTitles = true

  let style = UINavigationBarAppearance()
  style.configureWithDefaultBackground()

  style.titleTextAttributes = [.font: UIFont.systemFont(ofSize: 18)]

  self.navigationBar.standardAppearance = style
  self.navigationBar.compactAppearance = style


  //Configure Large Style
  let largeStyle = UINavigationBarAppearance()
  largeStyle.configureWithTransparentBackground()

  largeStyle.largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 28)]

  self.navigationBar.scrollEdgeAppearance = largeStyle

  }
 }
于 2019-11-19T19:11:38.173 回答
2

通过故事板之夜更改属性我有一些见解。通常当我被卡住时,我会反映我以编程方式对情节提要所做的相同更改,而代码中留下的东西通常是导致我的错误的东西。如果可能的话试试这个

于 2019-11-24T07:50:28.790 回答