Seong Min Choo
Seong Min Choo

Reputation: 147

Issue with Swift programmatic auto-layout constraint

I am simply using

toolBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0).isActive = true 

for setting up my topAnchor.

However, when I change the constant from 0 to an actual number, the console gives me

[LayoutConstraints] Unable to simultaneously satisfy constraints.

this error. I am calling this constraint in viewDidLoad but changing it to viewWillLayoutSubviews or other parts do not solve the problem.

How do I fix this error? Thank you!

Upvotes: 2

Views: 301

Answers (2)

Seong Min Choo
Seong Min Choo

Reputation: 147

I Simply needed to put translatesAutoresizingMaskIntoConstraints = false

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100503

Because you create another one , you need to edit the current one

var topCon:NSLayoutConstraint!

topcon = toolBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0)

topCon.isActive = true

Then play with constant

topCon.constant = // anyNumber

Upvotes: 1

Related Questions