1

I have a constraint in my view controller that gets deactivated by the system for some reason when the app goes into the background and then coming back to foreground. I haven't been able to pinpoint who's deactivating the constraint. I subclassed NSLayoutConstraint to catch when it's deactivated but the precondition is never triggered. So I'm out of ideas why this is happening and how to prevent it.

@IBOutlet private(set) var testConstraint: TestConstraint!


class TestConstraint: NSLayoutConstraint {
    override var isActive: Bool {
        didSet {
            precondition(isActive, "isActive should not be set to false")
        }
    }
}
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • 1
    As a general rule, constraints to not get *"deactivated by the system for some reason "* ... try putting together a [mre] – DonMag Nov 08 '21 at 20:30

1 Answers1

1

If the constraint is not installed (deactivated) in interface builder for some reason it will be deactivated by the system.

I haven't found any documentation for this but I found this SO post which led me to test to activate the constraint in interface builder and sure enough it stays active when coming from the background.

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193