2017-06-30 7 views
0

stackViewといくつかの子を追加しようとしましたが、レイアウトエラーが発生しました。私は間違って何をしていますか?UIStackViewでレイアウトアンカーを使用するとエラーが発生する

trailinAchors定数がleadingAchors定数より低い場合、問題が発生しているようです。

self.stackview.axis = .vertical 
    self.stackview.alignment = .fill 
    self.stackview.distribution = .fill 
    self.stackview.spacing = 5 
    self.addSubview(self.stackview) 
    self.stackview.translatesAutoresizingMaskIntoConstraints = false 
    self.stackview.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true 
    self.stackview.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true 
    self.stackview.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true 
    self.stackview.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0).isActive = true 

    // Holder 
    let holderView = UIView() 
    holderView.backgroundColor = UIColor.red 
    self.stackview.addArrangedSubview(holderView) 

    // Subview 
    let view3 = UIView() 
    view3.backgroundColor = UIColor.orange 
    holderView.addSubview(view3) 

    view3.translatesAutoresizingMaskIntoConstraints = false 
    view3.topAnchor.constraint(equalTo: holderView.topAnchor, constant: 0).isActive = true 
    view3.bottomAnchor.constraint(equalTo: holderView.bottomAnchor, constant: 0).isActive = true 
    view3.leadingAnchor.constraint(equalTo: holderView.leadingAnchor, constant: 30).isActive = true 
    view3.trailingAnchor.constraint(equalTo: holderView.trailingAnchor, constant: -30).isActive = true 

エラー:

2017-06-30 17:38:37.124333+0200 XXXXX[83954:2132661] [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:0x61000028b680 H:|-(30)-[UIView:0x7f8dab565720] (active, names: '|':UIView:0x7f8dab566620)>", 
    "<NSLayoutConstraint:0x61000028b6d0 UIView:0x7f8dab565720.trailing == UIView:0x7f8dab566620.trailing - 30 (active)>", 
    "<NSLayoutConstraint:0x61000028b4a0 H:|-(0)-[UIStackView:0x7f8dab569320] (active, names: '|': XXXXX.MultipleBarGraphsView:0x7f8dab561190'What are you doing')>", 
    "<NSLayoutConstraint:0x61000028b3b0 UIStackView:0x7f8dab569320.trailing == XXXXX.MultipleBarGraphsView:0x7f8dab561190'Hur ofta svarar du r\U00e4tt?'.trailing (active)>", 
    "<NSLayoutConstraint:0x61000028b900 '_UITemporaryLayoutWidth' XXXXX.MultipleBarGraphsView:0x7f8dab561190'Hur ofta svarar du r\U00e4tt?'.width == 0 (active)>", 
    "<NSLayoutConstraint:0x61000028af00 'UISV-canvas-connection' UIStackView:0x7f8dab569320.leading == UIView:0x7f8dab566620.leading (active)>", 
    "<NSLayoutConstraint:0x61000028bbd0 'UISV-canvas-connection' H:[UIView:0x7f8dab566620]-(0)-| (active, names: '|':UIStackView:0x7f8dab569320)>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x61000028b6d0 UIView:0x7f8dab565720.trailing == UIView:0x7f8dab566620.trailing - 30 (active)> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

答えて

0

に0>テーブルビューのスーパービューが適切に独自のスーパーに拘束されていることを確認します(ビューコントローラすることができる)ので、フレームは、幅と高さを持っています関数。これを取り除くと、エラーは消えてしまいました。

0

これはである何を見ますか?私は、テーブルビューのスーパービューの先頭と末尾のアンカーが同じ値(同じ場所)を持つ可能性があると考えています。私はの下部に

layoutIfNeeded() 

と呼ばれることに気づい

関連する問題