2014-06-30 52 views
0

我一直在尋找一種解決方案,在進入背景時不會捕獲緩存中的屏幕截圖。我發現我可以通過在AppDelegate中調用UIImageView並捕獲不是我的屏幕而是自定義圖像。當從後臺返回時卡在UIImageView上

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

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds]; 

     imageView.tag = 101;  
     imageView.backgroundColor = [UIColor blackColor]; 

     [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView]; 
} 

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

UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; 
[imageView removeFromSuperview]; 
} 

我的應用程序一段時間後註銷用戶,顯示了一個錯誤該用戶已註銷並返回到主視圖。但現在當應用程序在後臺註銷時,它不會在回到應用程序時刪除該應用程序。我應該如何刪除那個UIImageView

+0

在註銷方法中,寫入您在applicationWillEnterForeground方法中編寫的相同的兩行代碼 –

回答

0

用強大的指針握住你的imageView!

@property (strong, nonatomic) UIImageView *imageView; 
//... 
- (void)applicationDidEnterBackground:(UIApplication *)application { 

     self.imageView = [[UIImageView alloc] initWithFrame:self.window.bounds]; 
     self.imageView.backgroundColor = [UIColor blackColor]; 

     [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView]; 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    [self.imageView removeFromSuperview]; 
} 
相關問題