自定义导航标题偏移量iOS 11 [英] Custom Nav Title offset ios 11

查看:61
本文介绍了自定义导航标题偏移量iOS 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的导航项目标题,它只是两个标签,一个标签从一个.xib文件加载到另一个标签上.

I have a custom navigation item title that is simply two labels, one on top of the other, loaded from a .xib file.

通过调用此代码进行加载:

It's loaded by calling this:

class Utilities {
  /// Title and subtitle format custom title in Navigation bar.  Top and bottom text are centered on one another.
  ///
  /// - Parameters:
  ///   - navigationItem: The receiving controller's navigation item.
  ///   - titleText: Top text to be displayed a little larger and more bold.
  ///   - subtitleText: Bottom text to be displayed a little smaller and less bold.
  class func addCustomNavigationTitle(navigationItem: UINavigationItem, titleText: String, subtitleText: String) {
      let customNavigationTitleView =   LabelSubLabelCustomHeaderView.instanceFromNib() as! LabelSubLabelCustomHeaderView
      customNavigationTitleView.titleLabel.text = titleText
      customNavigationTitleView.dateLabel.text = subtitleText
      navigationItem.titleView = customNavigationTitleView
  }
  ...
}

它的定义是这样的:

class LabelSubLabelCustomHeaderView: UIView {
  @IBOutlet var titleLabel: UILabel!
  @IBOutlet var dateLabel: UILabel!

  class func instanceFromNib() -> UIView {
      return UINib(nibName: "LabelSubLabelCustomHeaderView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
  }
}

现在,它被精确下推了22个像素,从而隐藏了底部标签.

Now, it's pushed down by exactly 22 pixels, which hides the bottom label.

我必须在viewDidAppear中设置此视图的框架,以使其平直.我尝试了viewWillAppear和其他一些东西.我实际上必须隐藏它,设置它然后显示它,这显然是不正确的.

I have to set the frame of this view in the viewDidAppear in order to set it straight. I tried viewWillAppear and several other things. I'm literally having to hide it, set it, then show it, which is clearly not right.

在iOS 11之前,这没问题.

Prior to iOS 11, this worked no problem.

现在是这里,没有我的黑客修复程序,我希望我可以纠正:

Here it is now, without my hack fix, which I hope I can make right:

这是它的外观,iOS 10之前的外观以及使用我的hack修复程序后的外观:

And here is what it should look like, what it looked like prior to iOS 10, and how it looks with my hack fix:

还请注意,在为放开序列动画设置动画时,视图返回到错误的帧,因为帧太低了22个像素.我该如何解决?感谢您的任何帮助.

Also please note that when the unwind segue is animating, the view goes back to the incorrect frame, being 22 pixels too low. How can I fix this? Thanks for any help in advance.

更详细的约束信息:

推荐答案

您应该在自定义视图标题Xib中添加布局约束,以使下部标签与视图的安全区域之间的距离最小.有关iOS 10/11的完整工作示例,请参见 https://github.com/ekscrypto/Swift-Tutorial-Custom-Title-View

You should add a layout constraint in your custom view title Xib enforcing a minimum distance between the lower label to the safe area of the view. For a complete working example on iOS 10/11, see https://github.com/ekscrypto/Swift-Tutorial-Custom-Title-View

这篇关于自定义导航标题偏移量iOS 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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