0
私は、ユーザーが費やすことができ、収縮できる結果コンテナを持っています。私は制約を削除して新しい制約を追加したいと思います。それをクリックするとうまくいくが、もう一度クリックする(つまり、newConstraint.active = falseとresultTopConstraint = trueに設定するとクラッシュする)。 Unable to simultaneously satisfy constraints.
NSLayoutConstraintを再アクティブ化できますか?
を取得
@IBAction func toggleResultContainer(sender: AnyObject) {
isResultsOpen = !isResultsOpen
//resultTopConstraint.constant = isResultsOpen ? -300.0 : 0.0
self.view.sendSubviewToBack(searchView)
let newConstraint = NSLayoutConstraint(
item: resultsContainer,
attribute: .Top,
relatedBy: .Equal,
toItem: resultsContainer.superview!,
attribute: .Top,
multiplier: 1.0,
constant: 30.0
)
if(isResultsOpen){
resultTopConstraint.active = false
newConstraint.active = true
}else{
resultTopConstraint.active = true
newConstraint.active = false
}
UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.4, initialSpringVelocity: 10.0, options: .CurveEaseIn, animations: {
self.view.layoutIfNeeded()
}, completion: nil)
べきであり、上記のコードの作業と、これは本当に同時に満たす制約の問題です:私は、次がありますか?私は(https://stackoverflow.com/a/28717185/152825ごと)weak
とstrong
の両方に制約
@IBOutlet var resultTopConstraint: NSLayoutConstraint!
を設定しようとしたが、効果があるとは思われません。
THX - それを行うにはいないようです(ただし、偉大な提案を)。私はそれが有効な制約の衝突であるという強い意志を持っています。私はautolayoutで経験したことがないので、おそらく何か間違っています。 – timpone
ちょうど別の提案で私の答えを更新し、それが動作するか教えてください – Hazneliel
私はそれが動作すると思います!私は 'NSLayoutConstraint.deactivateConstraints([resultTopConstraint])'のような配列に入れなければなりませんでした。 thx – timpone