I have set a view's leading, trailing constraints normally. I have set its height to static 325. And for bottom constraint I have set 2 constraints 1. with main view's bottom constraint to view's bottom constraint. 2. with main view's bottom constraint to view's top constraint. Now on user's action I just show hide view with animation. So when view gets displayed on the screen and the app goes in background then the view's constraint automatically gets altered and the view gets hidden. This issue is only occurring in iOS 13 devices.
I tried to update its constraints on viewWillAppear() but in iOS 13 the viewWillAppear of ViewControllers is also not called when app is activated from background. Also I don't think , that this is a good idea to update constraints.
class ViewController: UIViewController {
@IBOutlet weak var topConstraint: NSLayoutConstraint!
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
self.topConstraint.isActive = false
self.bottomConstraint.isActive = true
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}
}
I don't want my constraints to be changed or updated when app state changes from foreground to background and vice versa.
Please help me with the same.
TIA
At the same time, didReceiveMemoryWarning is invoked for the app. At this point, so that your app continues to run properly, the OS begins terminating apps in the background to free some memory. Once all background apps are terminated, if your app still needs more memory, the OS terminates your app.
Helpful answersThe only apps that are really running in the background are music or navigation apps. Go to Settings>General>Background App Refresh and you can see what other apps are allowed to update data in the background. iOS dynamically manages memory without any user intervention. Thank you!
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.
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