views:

917

answers:

2

I have a mostly-navigation-bar-driven application. A few cases require the presentation of a modal view, and one of those cases requires the hiding of the status bar. However, even if I hide the status bar before presenting the modal view, the view is offset by 20 pixels.

Even if I set the frame of the modal view to 0,-20,320,480 after the view appears, it cuts off the top of the view.

I also want the user to be able to reveal the status bar (and a toolbar) upon tapping the screen, much the way the video player works. So I set the style to black transparent for this screen, and I would hope that hiding or showing the statusbar would not cause the view to jump up and down.

+1  A: 

Have you looked into the wantsFullScreenLayout property on UIViewControllers?

Jakob Dam Jensen
Unfortunately, I'm working in 2.x, not 3.0
Ed Marty
Why aren't you working on 3.0?
Jakob Dam Jensen
This is an api from 3.0. I don't think it's solveable in 2.x.. But I'm not sure at all...
Jakob Dam Jensen
I'm not working on 3.0 because we're targeting the lowest common denominator, and many people still don't have 3.0
Ed Marty
But unless your app is free or very cheap (guess all apps are =/).. What makes you think that people will buy your app if they wont even do the free upgrade (or the very cheap one on iPod touches)? It's not an attack on you - it's just a question. Is it really worth it?And aren't Apple requiring apps to be compiled to 3.0 for them to be on Appstore, or am I mixing up something?Do you have any numbers of how many of your users are on 2.x compared to 3.0?I'm just wondering... =)
Jakob Dam Jensen
Not compiled to 3.0, just tested and working on 3.0, using the compiler for 3.0, which can compile for 2.x. And it's not up to me, it's up to my boss, who is very hard to convince to drop an old OS/platform until the dead horse is well and truly beaten. But that's not the point.
Ed Marty
+2  A: 

Seeing from your comment below that you are targeting iPhone OS 2.x, I have a suggestion that might help.

Before presenting your modal view, do something like this:

  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
  [[self view] setFrame:CGRectMake(0, 0, 320, 480)];

Make sure that your modal view actually is 480px tall - one time I was fooled by the empty 20px space at the bottom. Turned out it was because my view was still 460px tall (to account for the status bar) so the code actually worked, but my view wasn't the right height.

When hiding your modal view, this works:

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[[self view] setFrame:CGRectMake(0, 20, 320, 460)];

You might have to twiddle the code a bit if you are using presentModalViewController - I tried this out using -addSubview because I was using a custom animation. But the basic principles should be the same (i.e. changing the parent view's frame).

Chu Yeow
I actually had already done something like this implementation, and it was working well enough on device that had 2.x On 3.0, however, this has more weird errors, for some reason, so I'm working on something that will use this for 2.x devices and will call [self setWantsFullscreenDisplay:YES] if [self respondsToSelector:@selector(setWantsFullscreenDisplay:)]. Not sure if that will work, but I'm taking a whack at it.
Ed Marty
What weird errors are you getting? I'm actually doing this in my OS 3.0 app and it's working fine.
Chu Yeow
Also, take a look at this SO question and the accepted answer for how to target the different OS versions: http://stackoverflow.com/questions/820142/how-to-target-a-specific-iphone-version
Chu Yeow