How do I know when a UIView is completely hiding?

I switch between two views by switching hidden attributes . How do I know when one view will be hidden and / or visible?

Tried setting breakpoints in viewDidLoad, viewDidUnload, viewWillAppear, viewWillDisappear, viewDidDisappear, startFirstResponder and resignFirstResponder. Nothing. None of them 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 on my own as this view ... subview is the subheading of the view under UITabBarItem. Apple docs reported that the configuration is unnatural and some automatic notifications must be done manually . Is this the same problem when you do not get startFirstResponder and resignFirstResponder that should be associated with hidden status?

+4
source share
2 answers

Guess that the Apple docs were correct - or at least suggested one way to solve the problem . Since I do not receive automatic notifications in subViews, but I receive them in mainView, I simply "forward" notifications 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!

+3
source

One option is to use Key-Value Observation to monitor the hidden property for both views. When the change is triggered, you will receive a message about the change.

+3
source

Source: https://habr.com/ru/post/1301708/


All Articles