Constraints resets when app is going in background - iOS 13 Constraints resets when app is going in background - iOS 13 swift swift

Constraints resets when app is going in background - iOS 13


Also met this issue. Noticed that constraints keep reseting in case if they are not checked Installed in Interface Builder. So, as workaround keep all constraints Installed in IB and change isActive state just in code.

enter image description here


The workaround that worked for me was to listen for UIApplication.willEnterForegroundNotification, and set isActive on all constraints at this point.

This notification seems to be published after the system (incorrectly) resets all constraints to their IB states, and before the app becomes visible again. So it's the perfect time to fix the constraints.

One caveat: when your constraints are contained in an autosizing table view cell, this notification seems to be triggered after the system calculates the height of the cell. So, you will need to trigger the table view to recalculate cell heights after updating your constraints (see this question for info on how to do that).


I found the issue is happening only in iOS 13.0 and above, Please try to make the constraint changes in ViewDidLayoutSubviews

      override func viewDidLayoutSubviews() {    super.viewDidLayoutSubviews()            self.bottomConstraint.isActive = false            self.topConstraint.isActive = true    self.view.layoutIfNeeded()}