'how to solve the problem of overlapping views?
In my application there is a function showing animation:
func showAnimation() {
let animatedViewController = AnimationViewController(name: "")
animatedViewController.modalPresentationStyle = .overFullScreen
animatedViewController.modalTransitionStyle = .crossDissolve
self.present(animatedViewController, animated: true, completion: nil)
}
When the application starts in viewdidload, the animation function (showAnimation) and the data loading function are launched. The problem is that in case of unsuccessful loading of data, an alert or a full screen with an error should appear, but at this point the animation still continues to be shown. View is not displayed and an error occurs:
[Presentation] Attempt to present (SomeViewController) on (UITabBarController) (from MyApp.MainViewController) while a presentation is in progress.
how can i fix it?
Solution 1:[1]
With a little understanding, I solved the problem in this way: There is my error showing func -
private func showFullScreenError(with error: Error,
action: (() - void)? = nil, actionAfterDismiss:action: (() - void)? = nil) {
let errorVC = ErrorFullScreenViewControllr(
eeror = error,
action = action,
actionAfterDismiss: actionAfterDismiss)
//This is where we check if our view is currently presenting anything else
if let nowShowingVC = self.presentedViewController {
//The most important thing here is that if you close the view not in a
//completion, then the view will not have time to close before you try to open a new one.
nowShowingVC.dismiss(animation: false) {
self.present(errorVC,animated: true)
} else {
self.present(errorVC,animated: true)
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AlexM |
