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
contentView
below the bottom (so it's "off-screen"), then you want to animate it moving up into view... Then, app goes to background, and you want the view to still be showing when app comes back to foreground? No new animation? – Overelaborate.frame = ...
statements), then your code should be working fine.ViewDidLoad()
should not be called when the app transitions from background to foreground, unless you have some other code running on that event. – Overelaborate