I am trying to find out how I can prevent a layout of views to interfere with an ongoing animation of the same view.
My app has a tabbar at the bottom of the screen controlled by a UITabBarController. In certain situations, the tabbar needs to animate sliding down and out of view. That works fine with code similar to the following test code (the menuController is the UITabBarController).
UIView.animate(withDuration: 2, delay: 0, options: .curveEaseIn) {
var frame = self.menuController.tabBar.frame
frame.origin.y += frame.size.height
self.menuController.tabBar.frame = frame
} completion: { finished in
self.menuController.tabBar.isHidden = true
}
But in some circumstances, a completely independent view controller is presented as a popup while the animation is in progress. That messes with the animation; the tabbar suddenly jumps upwards a bit and continuous moving down from there.
I have determined that the likely cause is that something triggers a new layout of the tabbar, although I don’t know how and why that happens in the full app. I can simulate the effect by triggering a layout myself in the test code:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
self.menuController.view.setNeedsLayout()
})
So my question is: how can I prevent the layout interfering with the animation and/or prevent the layout from happening while the animation is in progress.