views:

1828

answers:

2

I have a paged scrollview. Each page has a viewcontroller (buttonViewController) that manages a grid of buttons. If you press one of the buttons, the buttonViewController pops up another viewcontroller (detailViewController) modally.

The problem is, when I dismiss the modal view controller, the visible buttonViewController is shifted down by what looks like about 20 pixels. The weird thing is that only the visible page is shifted. If I scroll over to another page that is already loaded, it is still in the correct position.

My question is basically the same as http://stackoverflow.com/questions/1002613/dismissing-modalviewcontroller-moves-main-view-buttons-around-iphone

However, the accepted answer to that question assumed that the status bar is hidden. I am not hiding the status bar in my application.

Any other ideas?

One more note: The shift only happens the first time I launch a modal view controller. If I keep opening and closing the modal view controller, everything stays the same.

One further note: if I add the following code:

    CGRect frame = self.view.frame;
frame.origin.y=0;
self.view.frame = frame;

after I dismiss the modal view controller, then I can work around the problem. The frame seems to move by 20pixels in y. I still don't know what's causing the move though.

+1  A: 

Well I had this problem and it was due to the way my first viewController was set up (on the UIWindow), it is very weird since this had never happened to me before, the behavior i was observing was that when you add a subview at point (0,0) it would overlap with the status bar, which is not usual, usually the views know about the status bar and they behave appropriatly. As a side effect, when one pushes a modal view that takes off the status bar, after dismissing it I saw the same problem you are seeing. What i did to fix was to set the UIWindows view to my controllers view in the nib, this seemed to fix everything. Once again I dont know why simply adding to the window programatically with CGRectMake(0,0,320,460) had this odd behavior, since i have been doing this for all my previous projects and saw the correct behavior. But when i set it up in the nib, it worked as expected. Maybe this is your problem as well.

Daniel
I'm not sure I totally understand. UIWindow doesn't have a view property, I thought UIWindow *was* a view.Right now I'm adding my view to the window with: [window addSubview:scrollViewController.view];
Nathaniel Martin
Also, the modal view controllers don't hide the status bar.
Nathaniel Martin
In my case the modal view was hiding the status bar (but maybe that wasnt what was cuasing the problem ,it was that the modal view was being pushed), but to see what i done through the nib, go to XCode make a new project and select View based (this will create a controller with a view), look in the MainWindow nib, you will see what i mean
Daniel
A: 

Turns out this was related to: http://stackoverflow.com/questions/1195538/modalviewcontroller-doesnt-display-during-animation-when-paged-scrollview-is-scr

I had mismatched the heights of some of my viewcontrollers, and that was throwing everything off.

Some of the views had heights of 460pixels, some had 480pixels. For some reason, this made it shift by 20pixels evertime a modal view controller disappeared. Once I made everything 460pixels, everything worked great.

Nathaniel Martin