当应用程序处于事件状态时,我们如何找到当前哪个 View 是第一响应者。我知道应用程序委托(delegate) applicationWillEnterForeground 和 applicationDidBecomeActive 在某些情况下会被调用,我如何使用它来亲密查看第一响应者。
我用谷歌搜索,堆栈溢出没有找到确切的答案。有什么想法 friend ..
最佳答案
获取对 iOS 应用程序中最顶层 View /窗口的引用
topMostView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
引用getting-reference-to-the-top-most-view-window-in-ios-application链接。
编辑启动当前 View 的操作以在应用程序从后台返回时执行
Add BOOL applicationFromBackground; make its property in appDelegate.
Intially it will be applicationFromBackground = FALSE; in application didFinishLaunchingWithOptions method;
现在应用程序进入前台:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
applicationFromBackground = TRUE;
}
现在在所有 View Controller 的 View 中都会出现方法,该方法将为最顶层的 View Controller 调用,因此请执行以下操作:
- (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.
}
}
关于iphone - 当应用程序进入前台时查找当前 View 。 IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12274627/