I've made a constraint in my storyboard and connected to a variable in my view controller. In updateViewConstraints
I set the constraint's active
property to false.
When I do
self.view.setNeedsUpdateConstraints()
self.view.layoutIfNeeded()
in viewDidLoad
, layoutIfNeeded
calls updateViewConstraints
which sets the constraint to not active, but then somewhere after this it sets the constraint to active and then UIViewAlertForUnsatisfiableConstraints
symbolic breakpoint is hit due to conflict with my other constraints. When I check the value of .active
further up the stack at this breakpoint it is true
.
This only happens in viewDidLoad
. Before the view is displayed on the screen updateViewConstraints
is called again, and this time setting the constraint to not active sticks and the layout is correct. I still get the conflicting constraints error in the console. Is this a bug?
Edit: Here's the stack trace leading to setting the constraint to active:
The active
property is actually a virtual property that just indicates if the constraint is installed. If you set it true
, it installs itself into the nearest common ancestor of the two views. So it was becoming active because in storyboard it was installed in the view. To fix my problem, I simply unticked Installed
in storyboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With