Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9: Frame no longer set in viewWillAppear after UINavigationController pushViewController

I'm trying to solve a view placement bug that has arisen as of iOS 9. I am instantiating a view controller from a xib file (non-autolayout) and then pushing this onto my UINavigationController.

The problem is that when the view controller's viewWillAppear method is called, its frame has not yet been adjusted to the navigation controller's size and is still what was set in the xib file. It doesn't get set properly now until viewDidAppear.

This is completely screwing up my code. Does anyone know precisely what has changed that is causing this and what is the best way to handle it? I don't want to wait until viewDidAppear because this will look bad and make for a poor user experience.

like image 877
devios1 Avatar asked Sep 19 '15 00:09

devios1


1 Answers

I am also looking for the best fix.

My temporary one is to call the code that was in "viewDidAppear" in "viewDidLayoutSubviews". That way, my code will get called as soon as the frames are set.

But, make sure to add a boolean or something so that your code doesn't get called every time viewDidLayoutSubviews is called

-(void)viewDidLayoutSubviews{
   if (didLayoutSubviews == NO){
       didLayoutSubviews = YES;
       // perform code that was in viewWillAppear
   }
}
like image 161
NickProvost Avatar answered Oct 27 '22 16:10

NickProvost