iOS 13导航栏大标题问题

时间:2019-11-18 17:31:21

标签: ios swift xcode uinavigationbar uinavigationbarappearance

我正在尝试在Title中显示大的Navigation bar,但背景要清晰。向上滚动时,它将是带有模糊效果的Navigation bar

enter image description here

enter image description here

这看起来是正确的,但是,在滚动时,动画似乎已损坏。另外,过渡有时会卡住:

enter image description here

enter image description here

我的代码如下:

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

   }
}

UITableViewUINavigationController内部。两者都是通过叙事方式从情节提要中获得的。

4 个答案:

答案 0 :(得分:3)

嘿,您好,您的代码尝试删除此行

    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

  }
 }

答案 1 :(得分:2)

调试- 1)在视图调试器中,检查导航标题是否超出导航栏范围。

如果是这种情况,那么

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)
}

答案 2 :(得分:2)

通过分镜脚本之夜更改属性,我有一些见解。通常当我被卡住时我会反映出相同 我以编程方式对情节提要进行的更改以及代码中遗留的内容通常是导致我的错误的内容。尽可能尝试

答案 3 :(得分:2)

您可以尝试使用UITableViewController代替UITableview。我尝试使用UITableViewController及其对我来说工作正常。请检查以下设计和代码。

enter image description here

p, p span {
    font-size: 16px !important;
}

输出:-

enter image description here