gpt4 book ai didi

ios - applicationWillEnterForeground 呈现一个 View Controller

转载 作者:行者123 更新时间:2023-12-01 18:19:24 24 4
gpt4 key购买 nike

我有一个 PIN View Controller ,每次 - (void)applicationWillEnterForeground:(UIApplication *)application 时都需要显示它。火灾。我有多个 View Controller ,当应用程序进入后台时,用户可以在其中任何一个上。

问题是我不知道如何在当前处于事件状态的任何 View Controller 上显示 PIN View Controller 。这是我的实现的样子:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
ResourceSingleton *resource = [ResourceSingleton sharedSingleton];
if ([resource checkIfPINIsEnabled])
{
PinViewController *pinView = [[PinViewController alloc] initWithMode:kPINViewControllerModeEnter];
pinView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.window.rootViewController presentViewController:pinView animated:YES completion:NULL];
}
}

但是只有当我在第一个 View Controller ( Root View Controller )时才会出现 PIN View 。如何在任何 View Controller 上弹出它?

我看过 Using applicationwillenterforeground for a passcode screen但必须有更好的方法还是我错了?这将适用于 iOS 7,所以如果只有 7 具有这样的功能就可以了,但我很确定它也可以在 6 上完成。

最佳答案

如果您的 Root View Controller 是 NavigationController,那么在大多数情况下推送或呈现应该可以工作。您已经准备好所有代码,只需创建一个导航 Controller 。唯一不起作用的情况是如果已经存在模态视图 Controller 。在这种情况下,需要首先解雇。

这是一个有点杂乱的实现,它也处理了这种情况。

AKPresentedViewController *pres = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"pres"];

UINavigationController *navi = ((UINavigationController*)self.window.rootViewController);
if (navi.presentedViewController) {
[navi.presentedViewController dismissViewControllerAnimated:YES completion:^{
[navi presentViewController:pres animated:NO completion:nil];
}];
} else {
[navi presentViewController:pres animated:NO completion:nil];
}

关于ios - applicationWillEnterForeground 呈现一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18539998/

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