![](/img/trans.png)
[英]How to add a responsive UIPageViewController inside an UIStackView programmatically?
[英]How to add nibs to a UIStackView programmatically
我正在嘗試從筆尖添加任意數量的視圖到UIStackView中。 問題是,如果只包含一個視圖,則該視圖會增長為填充整個堆棧視圖,而不是保持適當的寬度。 到目前為止,這是我的代碼:
friendStackView.autoresizingMask = .flexibleWidth
friendStackView.translatesAutoresizingMaskIntoConstraints = false
let friendView = Bundle.main.loadNibNamed("FriendView", owner: self, options: nil)?.first as! FriendViewController
friendStackView.addArrangedSubview(friendView)
friendView.heightAnchor.constraint(equalToConstant: 150).isActive = true
friendView.widthAnchor.constraint(equalToConstant: 120).isActive = true
它導致以下調試:
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x14eb9eb0 UIStackView:0x14ee6ed0.width == 500 (active)>",
"<NSLayoutConstraint:0x14ef83f0 XXX.FriendViewController:0x14ef2090.width == 120 (active)>",
"<NSLayoutConstraint:0x14def090 'UISV-canvas-connection' UIStackView:0x14ee6ed0.leading == XXX.FriendViewController:0x14ef2090.leading (active)>",
"<NSLayoutConstraint:0x14def230 'UISV-canvas-connection' H:[XXX.FriendViewController:0x14ef2090]-(0)-| (active, names: '|':UIStackView:0x14ee6ed0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x14ef83f0 XXX.FriendViewController:0x14ef2090.width == 120 (active)>
您在這里有一個沖突,stackView width = 500,並且您正在嘗試提供應該填充整個寬度120的子視圖
"<NSLayoutConstraint:0x14eb9eb0 UIStackView:0x14ee6ed0.width == 500 (active)>",
"<NSLayoutConstraint:0x14ef83f0 XXX.FriendViewController:0x14ef2090.width == 120
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.