繁体   English   中英

dismissViewControllerAnimated导致黑屏ios目标c

[英]dismissViewControllerAnimated causing black screen ios objective c

所以在我的应用程序中,我在视图控制器导航之间得到了空白屏幕。 我认为dismissViewControllerAnimated是罪魁祸首。 所以在一个地方我改变了下面的代码 -

[vc dismissViewControllerAnimated:YES completion:^() {
        BCDThankYouViewController  *thankuView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ThankyouView"];
        [[self topViewController ]presentViewController:thankuView animated:YES completion:nil];
    }];

使用以下代码 -

[vc dismissViewControllerAnimated:YES completion:nil];
BCDThankYouViewController  *thankuView=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ThankyouView"];
            [[self topViewController ]presentViewController:thankuView animated:YES completion:nil];

vc在哪里 -

 UIViewController *vc = self.presentingViewController;
    while (vc.presentingViewController) {
        vc = vc.presentingViewController;

    }

它奏效了。 但在我的应用程序的其他部分,我有如下代码 -

[weakPresentingViewController dismissViewControllerAnimated:_animateClosingModal completion:^{
            [weakSelf handleDelayedLoginActions:userInfo withPortfolio:portfolio];
        }];

我换了 -

[weakPresentingViewController dismissViewControllerAnimated:_animateClosingModal completion:nil];
            [weakSelf handleDelayedLoginActions:userInfo withPortfolio:portfolio];

但在我的下一页加载之前,我仍然看到一个空白屏幕。 在上面这段代码中,weakPresentingViewController是

id __weak weakSelf = self;
    UIViewController * __weak weakPresentingViewController = (UIViewController *)_loginManagerDelegate;

请告诉我这里有什么问题? 为什么我在页面加载之前会出现黑屏?

首先呈现视图控制器需要时间来完成它。

一旦你把代码放在dismiss块中,这意味着在关闭动画结束后,然后开始呈现,并且正如我们所知,呈现需要时间,所以关键窗口没有视图控制器的时间很短,当然你会看到黑屏。

当您将代码放出dismiss块时,代码将逐个调用,但是dismiss有一个持续很短时间的动画,所以当dismiss是动画时,执行视图控制器的代码,所以在很短的时间内解散动画后,我们现在可以看到被解雇的视图控制器后面的屏幕,然后,呈现完成,所以你看不到黑屏。

但我必须说,即使我们不会得到黑屏,也不意味着代码是好的。

在我看来,为应用程序创建更好的工作流程要好得多,例如present,dismiss,push,pop等,以避免关键窗口的空根视图控制器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM