I have two views that are part of a login process. On the top of the view I have a progress bar, which is animated to fill to the progress the new view represents.
Both Views are built the same way.
All my contents are inside a UIView contentView
, which have the following constraints:
contentView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
contentView.widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.9),
contentView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
ofcourse, all constraints are activated inside viewDidLoad. Inside viewWillAppear I calulate the progress, that the progressbar should display before the change loads and update the constraints:
progressFillConstraint = progressFill.widthAnchor.constraint(equalTo: progressBackground.widthAnchor, multiplier: progress)
progressFillConstraint.isActive = true
newProgressFillConstraint = progressFill.widthAnchor.constraint(equalTo: progressBackground.widthAnchor, multiplier: (currentPage/totalPages))
newProgressFillConstraint.isActive = false
self.view.layoutIfNeeded()
Inside ViewDidAppear I then calculate the new progress and animate the change:
defaults.set(currentPage, forKey: "signupProcessProgress")
progressFillConstraint.isActive = false
newProgressFillConstraint.isActive = true
let animationDuration = 2.0
UIView.animate(withDuration: animationDuration) {
self.view.layoutIfNeeded()
}
And here lies the problem. For some wierd reason, it works very well exept one thing. The View loads as if I set the top constraint of the contentview to view.topAnchor and not to view.safeAreaLayoutGuide.topAnchor and animates as I call self.view.layoutIfNeeded() inside my progress Animation from viewDidAppear. So the View starts further top and animates down. I don't understand why since I never change the top constraint of the contentView. To me it seems as if the safeAreaLayoutGuide changes between viewWillAppear and viewDidAppear.
What am I missing here?