代码之家  ›  专栏  ›  技术社区  ›  der_Fidelis

如何以编程方式将nib添加到UIStackView

  •  0
  • der_Fidelis  · 技术社区  · 7 年前

    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)>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Shehata Gamal    7 年前

    这里有一个冲突,stackView width=500,您试图给出子视图,它应该填充整个宽度120

    "<NSLayoutConstraint:0x14eb9eb0 UIStackView:0x14ee6ed0.width == 500   (active)>",
    "<NSLayoutConstraint:0x14ef83f0 XXX.FriendViewController:0x14ef2090.width == 120