applicationWillEnterForeground呈现一个视图控制器 [英] applicationWillEnterForeground present a view controller
问题描述
我有一个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屋!