3

I have a problem with top 20px behind status bar, specifically I cannot put anything there.

When I created the UI I used the storyboard approach and set status bar style to translucent black. But when do the layout in Xcode my views' height is fixed to 460px (grayed out).

Please help.


Got an answer from a friend, will mark his solution as right answer as soon as he posts it here. For now here is the solution:

  1. In Interface Builder set up the view controller as wanting full screen and of freeform size: http://cl.ly/0x1p1u3q3B1y3b3C3U2n
  2. Then in the view's size settings set its height to 480px: http://cl.ly/1p1b0e060p1Y37393D08
  3. Ensure status bar style is translucent black in the Info.plist: http://cl.ly/153Y391S1b0G3J3z3Y1O
  4. Get satisfactory result: http://cl.ly/0Q1M390i3A3h2F3u2T19
Ivan Karpan
  • 1,554
  • 15
  • 20
  • Do you mean you want to (1) put views underneath the status bar, such that they're visible through it, or (2) make the status bar disappear and fill the 480 pixel height of the screen with your app? I believe that (1) is impossible, even though the "translucent" implies that it's translucent for something. – Cowirrie Apr 10 '12 at 09:35
  • It is the first option... And it is possible, my friend already helped me out with making it work. Waiting for him to post his solution to here to give him credit. – Ivan Karpan Apr 10 '12 at 11:26

4 Answers4

7

Here's solution without single line of code.

  1. In Interface Builder set up the view controller as wanting full screen and of freeform size.
  2. In the view's size settings set its height to 480px
  3. Ensure status bar style is translucent black in the Info.plist.
  4. Launch and observe

See the links for screenshots of each step in the top post.

2

Okay, having been told it's possible, I tried placing a view on top of the main view and setting its y coordinate to -20. Then I west to Info.plist and set Status bar style to Transparent black style (alpha of 0.5). The view I placed was visible beneath the status bar.

enter image description here

This only happened at run time; in Interface Buider the simulated translucent status bar is gray but opaque.

Edit: If you want to move your view controller's main view into this space, it is possible during viewWillAppear. (If you try to move it during viewDidLoad, it gets moved back afterwards.)

- (void)viewWillAppear:(BOOL)animated;
{
    [super viewWillAppear:animated];

    // Move the main view upwards if it isn't already there.
    CGRect frame = [[self view] frame];
    frame.size.height += frame.origin.y;
    frame.origin.y = 0;
    [[self view] setFrame:frame];
}

However, it gets moved back after rotation, and my attempts to respond to rotation ended up breaking the cell layout if I did this to a UITableView.

Here is the Swift version. Seems to work. Good solution for taking those App Store screen shots (well in addition to making the info.plist changes.

override func viewWillAppear(animated: Bool) {

    super.viewWillAppear(animated)

    // Move the main view upwards if it isn't already there.
    var frame: CGRect = self.view.frame
    frame.size.height += frame.origin.y
    frame.origin.y = 0
    self.view.frame = frame
}
Community
  • 1
  • 1
Cowirrie
  • 7,218
  • 1
  • 29
  • 42
  • This is not something I can really do if I have a UITableViewController in a storyboard and I want to have static cells in it. – Ivan Karpan Apr 10 '12 at 13:48
  • Thanks a lot for the input. The solution I mentioned my friend came up with actually allows avoiding any coding and results in perfectly working outcome. I will update my question with it and wait until he posts it here so I can mark it as an answer. – Ivan Karpan Apr 11 '12 at 08:00
1

Just make negative Y (-20) coordinate in interface builder.

invoodoo
  • 3,905
  • 1
  • 18
  • 16
-1

Try changing the value for "Status Bar" in the "Simulated Metrics" section of the Attributes inspector in Interface Builder. If you set it to "Inferred", Xcode will make no assumptions about the view controller, allowing you to set the size of the view to ANY size you want (even sizes that don't make any sense). Check out this post about the status bar for info on hiding it in your app.

Community
  • 1
  • 1
samson
  • 1,152
  • 11
  • 23
  • Hi, changing simulated parameters of views had no effect on the result in simulator. – Ivan Karpan Apr 10 '12 at 11:25
  • Changing those values will only hide the status bar in interface builder. You have to _also_ use `setStatusBarHidden:...`, as discussed in the post I linked to. – samson Apr 10 '12 at 16:50
  • The goal is not to hide the status bar but have it present on the screen with translucent black style and being able to put something underneath it. – Ivan Karpan Apr 11 '12 at 07:58
  • I see. Can I ask _why_ you would want to do that? IMHO, it looks a bit awkward... – samson Apr 11 '12 at 16:01
  • Well as an example look at Photos app and how it handles viewing pictures. When you tap the photo view you get translucent controls, which include status bar as well, and you can still through all of them. – Ivan Karpan Apr 11 '12 at 19:29