How to refresh the screen before applicationDidBecomeActive?

I need to hide something on the screen when the user activates the application, switching it to the foreground.

I tried pasting my code into applicationDidBecomeActive or applicationWillEnterForeground, and although it works OK, the old screen with the text I want to hide is displayed instantly.

How to hide the field before the screen is redrawn?

thanks

iphaaw

+4
source share
3 answers

I think the problem is that iOS will take a screenshot from your application the moment it goes to the background, so the animation will work in an instant.

The only way, in my opinion, to do this is to hide / close your opinion at the moment when the application goes to the background.

+2
source

Write the code in applicationWillResignActive: to "hide" everything you need to hide.

+2
source

I came across a similar situation, but instead of hiding, I wanted to show a block code screen to provide access. In any case, I think the solution also applies to your needs.

I often implement a custom base view controller in iOS apps. Therefore, instead of dealing with applicationDidBecomeActive: or applicationWillResignActive: I configure this view controller to listen for equivalent notifications:

 @interface BaseViewController : UIViewController - (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification; - (void)grantAccessWithNotification:(NSNotification *)notification; @end @implementation BaseViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self addNotificationHandler:@selector(grantAccessWithNotification:) forNotification:UIApplicationDidBecomeActiveNotification]; [self addNotificationHandler:@selector(prepareForGrantingAccessWithNotification:) forNotification:UIApplicationWillResignActiveNotification]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)prepareForGrantingAccessWithNotification:(NSNotification *)notification { // Hide your views here myCustomView.alpha = 0; // Or in my case, hide everything on the screen self.view.alpha = 0; self.navigationController.navigationBar.alpha = 0; } - (void)grantAccessWithNotification:(NSNotification *)notification { // This is only necessary in my case [self presentBlockCodeScreen]; self.view.alpha = 1; self.navigationController.navigationBar.alpha = 1; ... } @end 
0
source

All Articles