0

我已经改变了我的应用程序在进入后台时的行为,所以它会拍摄快照,对其应用模糊效果,然后将 UIImageView 推送到 rootViewController 的子视图中。它在设备上完美运行(不是在模拟器上......),但是当我回来时,我的导航控制器的按钮停止工作。如果我将应用程序置于后台,然后再次返回,我会看到我点击的控制器。

这是我的代码:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    UINavigationController* topViewController = (UINavigationController*)window.rootViewController.topViewController;
    NSLog(@"%@",topViewController.class);
    UIImage* snapshot = [[topViewController topViewController].view takeSnapshot];
    overlay = [[UIImageView alloc] initWithImage:[snapshot applyDarkEffect]];
    [[topViewController topViewController].view addSubView:overlay];
}

applyDarkEffect 是来自苹果示例应用程序的类别,而 takeSnapshot 是我在堆栈溢出时找到的类别。

当我的应用恢复活力时的代码:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    [overlay removeFromSuperview];
}

覆盖是我的应用程序委托的属性;

takeSnapshot 属于 UIView 的一个类别:

- (UIImage *)takeSnapshot {
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);

    [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];

    // old style [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
} 

另外,我的 rootViewController 是一个UINavigationController.

4

1 回答 1

0

我发现问题了!

“新”样式捕获导致了问题:[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];

我不得不使用“旧”风格:[self.layer renderInContext:UIGraphicsGetCurrentContext()]

于 2013-10-10T09:43:12.060 回答