5

如何调试以下问题?有没有办法解决这个问题?如何在通知内容扩展中使用Multiline UILabel/autolayout调试布局

在布局多线UILabel时,似乎在iOS 10.2及更低版本中存在一个错误。

我有我在这两个应用程序,并通知内容扩展使用一个相当简单的UIView子类,看起来像这样:

custom UIView subclass in interface builder

在主应用程序,一切都奠定了就好:

correct layout when shown in the main app

当在iOS 10.2及更低版本的通知内容扩展中显示时,布局已损坏。但只有当文本足够长时才能分成多行。好像iOS版无法计算整个视图的正确高度:

broken layout in iOS 10.2

然而,这个问题似乎是固定在iOS 10.3和更新:

correct layout in iOS 10.3

回答

0

我开始尝试子视图,特别是通过设置固定的高度限制。

事实证明,这是不与计算的总高度,但宽高比约束导致问题的标签(一个或多个):在最高的视图(宽度高度)。

编程计算基于视图的宽度和高度设置高度约束受影响的看法有助于解决这个问题:

public override func updateConstraints() { 
    super.updateConstraints() 

    if #available(iOS 10.2, *) { 
     imageContainerHeightConstraint.isActive = false 
    } else { 
     // FIX: multiline label/aspect ratio/autolayout bug in iOS < 10.2 
     let ratio: CGFloat = imageContainerAspectRatioConstraint.multiplier 
     imageContainerHeightConstraint.constant = round(bounds.width/ratio) 
     imageContainerHeightConstraint.isActive = true 
    } 
}