2017-04-21 11 views
0

上から下の3つのビューがあります:redView、yellowView、blueView。 blueViewをredView以下にするために、yellowViewを非表示にしてblueViewの制約を変更したいと思います。 絵は以下の通りです: this picture is original this picture is what I want コードは以下の通りです:あなたは、黄色のビューのセット高さ制約を必要とするSnapkitを使用して他のビューを非表示にしたときのビューの制約を更新するにはどうすればよいですか?

private lazy var redView: UIView = { 
    let redView = UIView() 
    redView.backgroundColor = UIColor.red 
    return redView 
}() 
private lazy var yellowView: UIView = { 
    let yellowView = UIView() 
    yellowView.backgroundColor = UIColor.yellow 
    return yellowView 
}() 
private lazy var blueView: UIView = { 
    let blueView = UIView() 
    blueView.backgroundColor = UIColor.blue 
    return blueView 
}() 
override func viewDidLoad() { 
    super.viewDidLoad() 
    view.addSubview(redView) 
    view.addSubview(yellowView) 
    view.addSubview(blueView) 
    redView.snp.makeConstraints { (make) in 
     make.top.left.right.equalTo(view) 
     make.height.equalTo(40) 
    } 
    yellowView.snp.makeConstraints { (make) in 
     make.top.equalTo(redView.snp.bottom) 
     make.left.right.height.equalTo(redView) 
    } 
    blueView.snp.makeConstraints { (make) in 
     make.top.equalTo(yellowView.snp.bottom) 
     make.left.right.height.equalTo(yellowView) 
    } 

}

if yellowView.isHidden == true { 
     //how is the code? 
    } else { 
     //how is the code? 
    } 

答えて

0

とyellowViewのその高さ制約のためにIBOutletを取ると変更しますhide/showごとの定数です。

if yellowView.isHidden == true { 
      //how is the code? 
      ibHeightOutletOfYellow.constant = 0; // hide here 
     } else { 
      //how is the code? 
      ibHeightOutletOfYellow.constant = 50; // as per your needed 

     } 
関連する問題