gpt4 book ai didi

ios - 导航工具栏在应用程序重新启动时隐藏

转载 作者:行者123 更新时间:2023-11-28 22:55:01 25 4
gpt4 key购买 nike

我有一个基于导航的应用程序,其中一个 View 显示了一个工具栏。如果我按 Home 键并重新进入应用程序,工具栏会自行隐藏。我试图在 viewDidAppear/viewWillAppear 中取消隐藏,但它们从未触发。

取消隐藏工具栏的正确位置在哪里?

最佳答案

ViewDidAppear/ViewWillAppear 不会在应用程序进入前台时被调用。要处理进入前台的应用程序,您需要创建一个通知。

在 Appdelegate 中将以下代码添加到 applicationWillEnterForeground:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName: @"UIApplicationWillEnterForegroundNotification" object: nil];
}

然后在您各自的 View Controller 中进行以下更改

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleEnterForeground:)
name: @"UIApplicationWillEnterForegroundNotification"
object: nil];
}

- (void) handleEnterForeground: (NSNotification*) sender
{
//Do whatever you need to do to handle the enter foreground notification
}

关于ios - 导航工具栏在应用程序重新启动时隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11004243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com