简体   繁体   English

当应用从后台重新激活时,如何更改显示的iOS视图。

[英]How to change iOS view displayed when app reactivates from background.

I have a root view controller that opens up a new modal view controller. 我有一个根视图控制器,可以打开一个新的模式视图控制器。 When the app goes to the background I dismiss the top view but when the app opens up again, there is a split second that I see the view I just have dismissed and then the root view displays. 当应用程序进入后台时,我关闭了顶视图,但是当应用程序再次打开时,有一瞬间,我看到了我刚刚关闭的视图,然后显示了根视图。

How can I prevent the top view from showing up when the app becomes active again. 当应用再次激活时,如何防止显示顶部视图。

I have tried to dismiss the top view on all the stages I could think on the app delegate (applicationWillResignActive, applicationDidEnterBackground, applicationWillEnterForeground, applicationDidBecomeActive) as well on viewWillDisappear on the top view itself without success. 我试图在我可能想到的应用程序委托的所有阶段(applicationWillResignActive,applicationDidEnterBackground,applicationWillEnterForeground,applicationDidBecomeActive)上关闭顶视图,并且在顶视图本身上的viewWillDisappear都没有成功。 The view does dismiss but I can see it for a split second when the app becomes active. 该视图确实关闭,但是当该应用程序处于活动状态时,我可以在瞬间看到它。

Can someone help me to show the root view all the time when the application becomes active? 当应用程序激活时,有人可以一直帮助我显示根视图吗? I don't want to do anything with the launch image, that is working fine. 我不想对启动映像做任何事情,一切正常。 I just don't want the app to show other views but the root view after launching/ becoming active. 我只是不希望该应用显示其他视图,而是启动/激活后显示根视图。 If that is not possible then can I show an image till the root view controller is ready to be displayed? 如果那不可能,那么我可以显示图像,直到准备好显示根视图控制器为止吗?

Thanks. 谢谢。

At the end of applicationDidEnterBackground , the OS will take a picture of your UI. applicationDidEnterBackground的末尾,操作系统将为您的UI拍照。 Apple tell us this in the documentation : 苹果在文档中告诉我们:

When the applicationDidEnterBackground: method returns, the system takes a picture of your app's user interface and uses the resulting image for transition animations. 当applicationDidEnterBackground:方法返回时,系统将为您的应用程序的用户界面拍照,并将生成的图像用于过渡动画。 If any views in your interface contain sensitive information, you should hide or modify those views before the applicationDidEnterBackground: method returns. 如果界面中的任何视图包含敏感信息,则应在applicationDidEnterBackground:方法返回之前隐藏或修改这些视图。

But I bet you are dismissing your modal view controller animated in that, so when it takes the picture it will be taking the picture just as the view is being animated away. 但是我敢打赌,您将以这种方式取消使用动画的模态视图控制器的功能,所以当它拍摄照片时,它将像拍摄动画时一样拍摄照片。 You could try dismissing it not animated. 您可以尝试将其设为非动画状态。 It might then mean that during the transition to the background the user sees the root view controller, but I think you're just going to have to live with one of those options unfortunately. 这可能意味着在过渡到背景期间,用户会看到根视图控制器,但不幸的是,我认为您将不得不使用其中一个选项。

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

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