如何解决重叠视图的问题?

发布于 2025-01-30 06:37:37 字数 597 浏览 2 评论 0原文

在我的应用程序中,有一个显示动画的函数:

func showAnimation() {
    let animatedViewController = AnimationViewController(name: "")
    animatedViewController.modalPresentationStyle = .overFullScreen
    animatedViewController.modalTransitionStyle = .crossDissolve
    self.present(animatedViewController, animated: true, completion: nil)
}

当应用程序在ViewDidload中启动时,启动了动画功能(ShowAnimation)和数据加载功能。问题在于,如果数据失败了数据,则应出现警报或全屏,但此时仍将显示动画。视图未显示,并且发生错误:

[演示]尝试在(uitabbarcontroller)上介绍(someviewController)(来自myApp.mainviewController),而演示正在进行。

我该如何修复?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2025-02-06 06:37:37

有了一点了解,我以这种方式解决了问题:
我的错误显示了函数 -

    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)
                }
              }
            }

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)
                }
              }
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文