views:

582

answers:

3

Hi guys.

I'm using a UINavigationController to manage my UIViewControllers hierarchy. For one of these UIViewController, i need to change its view bounds programmatically (depending on specific conditions) so i used setBounds and it's working fine.

My issue is this : when i change this view bounds, then push another UIViewController to the UINavigationController stack and then pop the last UIViewController, my bounds changement are lost. I guess it's because my UIView is redrawn but i thought the bounds modification would still be live.

I can change my UIView bounds again after the view appeared but the user will notice the view bounds modification.

Any tips? Is it a common situation or is it because my UIView is loaded from a XIB and i missed a parameter or something?

Thanks :)

Edit : just noticed my UIView bounds are changed right before pushing the new UIViewController to the stack (during the animation)

A: 

Your view probable has autoresizing set. If you don't want that, set autoresizing to 0:

myView.autoresizingMask = 0;
Philippe Leybaert
Just tried but I still have this issue
Vivi
A: 

You probably want to do all of your bounds-setting (including the first time) in -viewWillAppear:. This should get called before you're put on screen in both the initial push and the pop case.

Rob Napier
That would be the best option but unfortunately i need to change the bounds from my UINavigationController delegate (since this bounds modification is independant from the view; the modification may happen on any of my views)
Vivi
The equivalent delegate method is navigationController:willShowViewController:animated:. What's happening when you re-set the bounds there?
Rob Napier
When i change the bounds in the willShowViewController method, my bounds are apparently overwritten before the display so, at the moment, the bounds modification is done in the didShowViewController
Vivi
A: 

Where are you changing the bounds? Maybe you should put it in something like viewWillAppear/didAppear so that the bounds are altered everytime the next View Controller is popped off of the stack?

bpapa
My bounds are changed by the UINavigationController delegate; I'm watching for my conditions with both willShowViewController and didShowViewController methods.
Vivi
Why not set a variable in willShowViewController that is read in viewWillAppear, and then based on the value the bounds are modified? It sounds kind of weird to modify a specific view from the Nav Controller Delegate anyway.
bpapa
I agree this is weird but this is the best solution we found to create an ads displayer which is independant of the application; we don't want to change the application and its view controllers to do so, so i need everything to be done within this delegate. When i change the bounds in the willShowViewController method, my bounds are apparently overwritten before the display so, at the moment, the bounds modification is done in the didShowViewController (that's the reason the user may notice the modification)
Vivi