Constraints resets when app is going in background - iOS 13
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()}