applicationWillEnterForeground 呈现一个视图控制器 [英] applicationWillEnterForeground present a view controller

查看:23
本文介绍了applicationWillEnterForeground 呈现一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PIN 视图控制器,每次 - (void)applicationWillEnterForeground:(UIApplication *)application 触发时都需要显示它.我有多个视图控制器,当应用进入后台时,用户可以在其中任何一个上.

I have a PIN view controller which needs to be presented every time the - (void)applicationWillEnterForeground:(UIApplication *)application fires. I have multiple view controllers and when the app enters background the user could be on any of them.

问题是我不知道如何在当前活动的任何视图控制器上显示 PIN 视图控制器.这是我的实现方式:

The problem is I don't know how to present the PIN view controller over any view controller that is currently active. Here's how my implementation looks:

- (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];
    }
}

但是只有当我在第一个视图控制器(根控制器)时才会出现 PIN 视图.如何在任何视图控制器上弹出它?

But the PIN view appears only if I'm at the first view controller (the root one). How to pop it up on any view controller?

我已经看到 使用 applicationwillenterforeground 作为密码屏幕 但必须是更好的方式还是我错了?这将适用于 iOS 7,所以如果只有 7 有这样的功能就可以了,但我很确定它也可以在 6 上完成.

I have seen Using applicationwillenterforeground for a passcode screen but there has to be a better way or am I wrong? This will be for iOS 7 so if only 7 has such a functionality its ok but I am pretty sure it can be done on 6 as well.

推荐答案

您可以让应用程序委托处理 PIN 视图的逻辑,并使其成为视图,而不是视图控制器.只需将视图添加为窗口的子视图,它就会显示在其他任何内容之上.

You could have the app delegate handle the logic for the PIN view, and have that be a view, rather than a view controller. Just add the view as a subview of the window, and it will be shown over anything else.

- (void)applicationWillEnterForeground:(UIApplication *)application {
    UINib *pinNib = [UINib nibWithNibName:@"PINView" bundle:nil];
    UIView *pinView = [pinNib instantiateWithOwner:self options:nil][0];
    [self.window addSubview:pinView];
}

如果您让应用委托 xib 的文件所有者,那么您可以将视图中所需的任何插座连接到应用委托.

If you make the app delegate the File's Owner of the xib, then you can hook up any outlets you need in the view to the app delegate.

这篇关于applicationWillEnterForeground 呈现一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆