Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在ApplicationIdentinterBackground中添加的视图在应用程序从后台返回之前不可见_Ios_User Interface_Window_Lifecycle_Multitasking - Fatal编程技术网

Ios 在ApplicationIdentinterBackground中添加的视图在应用程序从后台返回之前不可见

Ios 在ApplicationIdentinterBackground中添加的视图在应用程序从后台返回之前不可见,ios,user-interface,window,lifecycle,multitasking,Ios,User Interface,Window,Lifecycle,Multitasking,我在ApplicationIdentinterBackground的应用程序主窗口中添加图像视图: - (void)applicationDidEnterBackground:(UIApplication *)application { UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"splashimage.png"]]; splash.frame = s

我在ApplicationIdentinterBackground的应用程序主窗口中添加图像视图:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
        UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"splashimage.png"]];
        splash.frame = self.window.bounds;
        [self.window addSubview:splash];
}
我希望当我按下设备的主页按钮将应用程序置于后台,然后双击主页按钮查看任务管理器时,我会看到splashimage.png显示。但是,当应用程序进入后台时拍摄的屏幕截图似乎不包括这个覆盖图像视图。我想会的,因为我添加了没有动画的imageView

为什么会发生这种情况

更新:即使我在ApplicationIdentinterBackground中隐藏了我的窗口,在应用程序进入后台状态后,我仍然可以在任务管理器中看到完整的未隐藏窗口。当我按下home(主页)按钮时,该窗口仅在应用程序从后台返回后的一瞬间被隐藏

- (void)applicationDidEnterBackground:(UIApplication *)application
{
        //this does not work either!
        self.window.hidden = YES;
}
更新:顺便说一句,我知道ApplicationIdentinterBackground还有5秒要完成。我现在只测试了一次

self.window.hidden = YES;
在applicationIdentinterBackground中,applicationWillResignActive中没有任何内容,并且当应用程序进入后台时,窗口仍然不隐藏;只有当它返回前台时。这是在告诉我,在我的应用程序中,一定有其他东西不允许这种情况在ApplicationIdentinterBackground中发生。顺便说一下,如果我移动

self.window.hidden = YES;
对于applicationWillResignActive,当应用程序进入后台时,窗口将隐藏。但我正试图找出什么会阻止应用程序在ApplicationIdentinterBackground中完成这个单一、简单、非动画的任务。任何想法都值得赞赏

更新:这个问题与使用BannerViewController(iAd)有关。我在一个超宽带控制器中使用它。目前还不确定问题到底是什么,或者是否与UITabBarController中的使用有关

- (void)applicationWillResignActive:(UIApplication *)application {

    [bannerVC.view snapshotViewAfterScreenUpdates:YES];
}
更新:我认为这个问题与UITabBarController无关,但通常与BannerViewController(iAd)有关。现在要了解为什么

更新:BannerViewController.m中的此行导致了以下问题:

[self.view addSubview:bannerView]
在这种方法中:

- (void)viewDidLayoutSubviews
{
    CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;
    ADBannerView *bannerView = [BannerViewManager sharedInstance].bannerView;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
    NSString *contentSizeIdentifier;
    // If configured to support iOS <6.0, then we need to set the currentContentSizeIdentifier in order to resize the banner properly.
    // This continues to work on iOS 6.0, so we won't need to do anything further to resize the banner.
    if (contentFrame.size.width < contentFrame.size.height) {
        contentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        contentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }
    bannerFrame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSizeIdentifier];
#else
    // If configured to support iOS >= 6.0 only, then we want to avoid currentContentSizeIdentifier as it is deprecated.
    // Fortunately all we need to do is ask the banner for a size that fits into the layout area we are using.
    // At this point in this method contentFrame=self.view.bounds, so we'll use that size for the layout.
    bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];
#endif

    if (bannerView.bannerLoaded) {
        contentFrame.size.height -= bannerFrame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;
    } else {
        bannerFrame.origin.y = contentFrame.size.height;
    }
    _contentController.view.frame = contentFrame;
    // We only want to modify the banner view itself if this view controller is actually visible to the user.
    // This prevents us from modifying it while it is being displayed elsewhere.
    if (self.isViewLoaded && (self.view.window != nil)) {
        [self.view addSubview:bannerView];
        bannerView.frame = bannerFrame;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
        bannerView.currentContentSizeIdentifier = contentSizeIdentifier;
#endif
    }
}
更新:我意识到这段代码真的应该在ApplicationIdentinterBackground中。但是,AdBannerView似乎没有办法及时停止动画,以便实现这一点。因此,就目前而言,据我所知,ApplicationWillResignative是剩下的全部,但它给用户留下了“少于”的体验。如果您能就如何停止AdBannerView动画提供任何建议,我将不胜感激,这样快照就可以在ApplicationIdentinterBackground中显示,而不仅仅是在从后台返回时

更新: 要复制此问题,请执行以下操作:

  • 下载
  • 打开TabbedBanner示例
  • 将以下代码添加到AppDelegate:
  • 运行应用程序。(由于帧尚未更新,因此帧被弄乱,但此示例仍将显示问题)
  • 轻触home(主页)按钮一次,即可将应用程序置于后台
  • 双击主页按钮可在任务管理器中查看应用程序
  • 如果对applicationWillResignActive中的代码进行了注释,而对ApplicationIdentinterBackground中的代码未进行注释,则在任务管理器中不会看到蓝色启动屏幕。但是,如果您在ApplicationIdentinterBackground中对代码进行了注释,并在applicationWillResignActive中取消了对代码的注释,那么您应该会在任务管理器中看到蓝色的启动屏幕。然而,这是不可取的。问题是如何在ApplicationIdentinterBackground方法中显示启动屏幕

    - (void)applicationWillResignActive:(UIApplication *)application {
    
        //works - but undesirable
        //[self addDummyView];
        //[_tabBarController.view snapshotViewAfterScreenUpdates:YES];
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application {
    
        //does not work - needs to work to show dummyview only when application actually goes into the background
        [self addDummyView];
        [_tabBarController.view snapshotViewAfterScreenUpdates:YES];
    }
    
    - (void)addDummyView {
    
        UIView *topView = _tabBarController.view;
        UIView *colorView = [[UIView alloc] initWithFrame:topView.frame];
        [colorView setBackgroundColor:[UIColor blueColor]];
        [topView addSubview:colorView];
        [topView bringSubviewToFront:colorView];
    }
    

    你的代码很好。您应该知道,双击home(主页)按钮时不会调用
    ApplicationIdentinterBackground
    。当您切换到另一个应用程序或转到springboard时,将调用该应用程序

    所以,你应该只按一次主页按钮,然后双击它,你的应用程序的屏幕截图应该有图像视图。我在一个测试项目中复制了您的用例,它适合我


    如果仍不起作用,则应查看图像视图的图像是否为非零。哦,请不要隐藏应用程序窗口。

    当ApplicationIdentinterBackground方法返回时,应用程序当前视图的快照将用于多任务视图。未看到更新的原因是,快照是在绘图周期之前拍摄的。即使调用setNeedsDisplay,快照仍会在之前拍摄

    要等待视图更新(添加子视图后),请调用以下命令:

    [self.view snapshotViewAfterScreenUpdates:YES];
    

    值为
    YES
    。这将强制您首先渲染更改。你可以在这里的苹果文档中阅读更多关于处理类似内容的信息:

    你可以在这里得到答案:


    将您的代码保存在applicationWillResignActive中。

    谢谢您的评论。但我在上面说过,我将应用程序置于后台,首先“按下设备的主页按钮,然后双击主页按钮查看任务管理器”。此外,我只是隐藏应用程序窗口进行测试。我永远不会在应用程序中真正做到这一点。还有什么想法吗?请尝试在“[self.window addSubview:splash]”上设置断点,并测试imageView图像是否为nillIt或not nil。而且,正如我也提到的,我甚至无法用这种方法成功隐藏应用程序窗口。所以我想问题一定在应用程序的其他地方。可能与我使用故事板有关?也许与记忆有关?在测试项目中,我也使用故事板,所以这不是问题所在。尝试在ViewDiEnterBackground中设置断点,然后逐步执行,查看是否正确添加了imageView(在前面而不是后面)。另外,为了调试起见,请将图像视图的背景设置为红色,然后查看是否有新的内容。我已经检查了与视图相关的所有内容,一切正常。此时,我将重点放在一个事实上,即在ApplicationIdentinterBackground方法中,我甚至无法将窗口设置为隐藏。这表明