自定义导航标题偏移ios 11

我有一个自定义导航项标题,只是两个标签,一个在另一个上面,从.xib文件加载。

在此处输入图像描述

通过调用它来加载它:

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个像素,隐藏了底部标签。

我必须在viewDidAppear中设置此视图的框架才能将其设置为直线。 我试过了viewWillAppear和其他一些东西。 我真的不得不隐藏它,设置它,然后显示它,这显然是不对的。

在iOS 11之前,这没有问题。

现在,没有我的黑客修复,我希望我能做对:

在此处输入图像描述

以下是它应该是什么样子,它在iOS 10之前的样子,以及它在我的hack修复中的外观:

在此处输入图像描述

另请注意,当展开segue是动画时,视图会回到不正确的帧,22像素太低。 我怎样才能解决这个问题? 在此先感谢您的帮助。

编辑:更详细的约束信息:

视图 DateLabel

TitleLabel

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