Why does viewWillAppear not get called when an app comes back from the background?

I’m writing an app and I need to change the view if the user is looking at the app while talking on the phone.

I’ve implemented the following method:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"viewWillAppear:");
    _sv.frame = CGRectMake(0.0, 0.0, 320.0, self.view.bounds.size.height);
}

But it’s not being called when the app returns to the foreground.

I know that I can implement:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];

but I don’t want to do this. I’d much rather put all my layout information in the viewWillAppear: method, and let that handle all possible scenarios.

I’ve even tried to call viewWillAppear: from applicationWillEnterForeground:, but I can’t seem to pinpoint which is the current view controller at that point.

Does anybody know the proper way to deal with this? I’m sure I’m missing an obvious solution.

7 Answers
7

Leave a Comment