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