How to know when UIView becomes completely hidden?
I am switching between two views by toggling hidden attr开发者_JS百科ibutes. How would I know when one view gets hidden and/or visible?
Tried setting break points into viewDidLoad, viewDidUnload, viewWillAppear, viewWillDisappear, viewDidDisappear, becomeFirstResponder and resignFirstResponder. Nothing. None of those are called, when I set hidden = YES/NO.
if (self.aController)
self.aController.view.hidden = YES;
if (self.bController)
self.bController.view.hidden = NO;
[self.bController viewWillAppear:YES];
I call viewWillAppear by myself, since that view is... subview of subview of view under UITabBarItem. Apple docs told that the setup is unnatural and some automatic notifications have to be done manually. Is this the same problem with not getting becomeFirstResponder and resignFirstResponder which are supposed to be related to hidden status?
One option is to use Key-Value Observation to observe the hidden
property of either views. When the change is triggered, you'll get a message about the change.
Guess Apple docs were right - or at least offered one way to solve the problem. Since I don't get automatic notifications in subViews, but I do get them in mainView, I just "forward" the notifications by myself:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// called at tab switch
if (self.aController)
[self.aController viewWillAppear:YES];
if (self.bController)
[self.bController viewWillAppear:YES];
}
- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// called at tab switch
if (self.aController)
[self.aController viewWillDisappear:YES];
if (self.bController)
[self.bController viewWillDisappear:YES];
}
Not sure, if this is the "right" way, but it works. Next problem, please!
精彩评论