I have an app which has a UITabBarController, and when different tabs are pressed, I override viewWillAppear, get a reference to the tabBarController and then resize its frame. The reason for doing so is that some tabs require the full height of the screen, whilst other tabs have a background in the top 120pixels.
The way I am referencing the tabBarcontroller is by getting the application delegate and using its reference to the tabBarController to move its position:
MyAppDelegate *del= [UIApplication sharedApplication].delegate; del.tabBarController.view.frame = CGRectMake(0,120,320,360);
This method works fine when switching between tabs, but the first time the application loads up it does things a bit weirdly, and I cant understand why. My first tab actually has a NavigationBar, and then contains a view which has a pickerView. The first time my application loads, the NavigationBar appears about 10px too low, however the pickerView still appears in the right position. I was hoping I could get around this by treating things differently the first time viewWillAppear is called, however if I decrease the y position to compensate for the navigation bar, it shifts everything together including the datepicker within the view.
I would like to understand why the application behaves differently when first loaded and was hoping someone could either explain this to me and with any ideas on how to solve the issue or please point me in the right direction. I suspect this has something to do with the status bar on top since that is about the same size as the offset I am seeing..
Any help would be appreciated! thanks
OK I've figured it out. If anyone is interested, it appears that on application startup, the UINavigationBar
's frame has a y position of 10 pixels. All I had to do was set the UINavigationBar
's frame vertical position back to 0 pixels and all works! Anyone needing to do this, here's the code:
self.navigationController.navigationBar.frame = CGRectMake(0,0,320,45)
I call the above line in the viewWillAppear
method and all works as expected.