2013-10-08 58 views
0

當我的應用程序進入後臺時,它已經改變了我的應用程序的行爲,因此需要快照,對其應用模糊效果,然後將UIImageView推入rootViewController子視圖。 它在設備上完美工作(不在模擬器上...),但是當我回來時,我的navigationController按鈕停止工作。如果我把應用程序放到了背景上,然後又回到了我看到的控制器上。將子視圖添加到topViewController後,iOS7 ViewControllers將不會出現

這裏是我的代碼:

- (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

回答

0

我發現問題了!

「新」的風格捕捉引發的問題:[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];

我不得不使用「舊」風格:[self.layer renderInContext:UIGraphicsGetCurrentContext()]