私はボタンプレスで以下のコードを実行しますが、下側の制約は従わないようです。サブビュー(bandCardView)は、親ビュー(formVw)の一番下をオーバーフローします。どのようにこれらの制約に従うことができますか?プログラム上の制約に従わない
@objc private func cardBtnTouch(){
self.bandAccountView?.bankBtn.setSelected(selected: false)
self.bandAccountView?.cardBtn.setSelected(selected: true)
self.bandAccountView?.selectLbl.isHidden = true
for subview in self.bandAccountView!.formVw.subviews{
subview.removeFromSuperview()
}
self.bandAccountView!.formVw.addSubview(bandCardView!)
self.bandAccountView!.formVw.addConstraint(NSLayoutConstraint(item: self.bandAccountView!.formVw, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: bandCardView!, attribute: NSLayoutAttribute.top, multiplier: 1.0, constant: 0.0))
self.bandAccountView!.formVw.addConstraint(NSLayoutConstraint(item: bandCardView!, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.bandAccountView!.formVw, attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 0.0))
self.bandAccountView!.formVw.addConstraint(NSLayoutConstraint(item: bandCardView!, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: self.bandAccountView!.formVw, attribute: NSLayoutAttribute.leading, multiplier: 1.0, constant: 0.0))
self.bandAccountView!.formVw.addConstraint(NSLayoutConstraint(item: self.bandAccountView!.formVw, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal, toItem: bandCardView!, attribute: NSLayoutAttribute.trailing, multiplier: 1.0, constant: 0.0))
}
(時には、idkが必要なとき、またはなぜ必要なのか、いくつかのcustomViewsに必要です)....それぞれの制約の最後に 'isActive = true'と書いてください。また、 'translatesAutoresizingMaskIntoConstraints'が' false'に設定されていることを確認してください。それが動作するかどうかを確認する – Honey
@Honeyサブビューの自動サイズ変更マスクです。私はいつもその部分を忘れています。あなたが提出して答えたら、私は受け入れます。 – steventnorris
また、iOS 8をサポートしていない場合は、このように詳細な制約を作成するのを避け、代わりに 'topAnchor'、' bottomAnchor'などを使用することができます。[here](https://useyourloaf.com/blog/pain) -free-constraints-with-layout-anchors /)、または私の質問を参照してください[https://stackoverflow.com/questions/44008908/label-showing-top-of-screen-instead-of-being-on -the-inputaccessoryview) – Honey