应用程序进入前台时查找当前视图。 IOS [英] Finding the current view when application enter foreground. IOS

查看:76
本文介绍了应用程序进入前台时查找当前视图。 IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程式启用时,我们如何找出哪个资料检视目前是第一个回应者。我知道应用程序委托applicationWillEnterForeground和applicationDidBecomeActive将被调用的情况下,我如何使用这个亲密视图,这是第一个响应。

How do we find which view is presently first responder when application become active. I know application delegates applicationWillEnterForeground and applicationDidBecomeActive will be called in cases, how can I use this to intimate view which is first responder.

我有google和堆栈溢出没有找到确切的答案。任何想法的朋友..

I have googled and stack overflowed didn't find exact answer. Any idea friends..

推荐答案

获得iOS应用程序中最顶层视图/窗口的引用

Getting reference to the top-most view/window in iOS application

topMostView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];

请参阅获取引用到最高的视图窗口在应用程序链接。

EDIT 在应用程序从后台恢复时向当前视图执行的操作

EDIT intiate action to current view to perform when application returing from background

Add BOOL applicationFromBackground; make its property in appDelegate.

Intially it will be applicationFromBackground = FALSE; in application didFinishLaunchingWithOptions method;

现在应用程序进入前台:

Now application enters foreground :

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   applicationFromBackground = TRUE;
}

现在所有视图控制器的视图将出现的方法将被调用为topmost viewcontroller所以这样做:

Now in all view controllers's view will appear method which will be called for topmost viewcontroller so do this:

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  // Create AppDelegate instance
  AppDelegate *objAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  if(objAppDelegate.applicationFromBackground)
  {
     applicationFromBackground = FALSE;
     //do what u want.
  }

}

这篇关于应用程序进入前台时查找当前视图。 IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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