drekka wrote:
Hmm, would I be correct in assuming that views automatically assume they are being added to windows and therefore shift themselves down 20 pixels?
Close... But UIView isn't the culprit. Generally when a content view (view that wants to be full-screen) is shifted up or down 20 pixels from where it belongs, it's because the view controller isn't cooperating with IB (or in some cases because there isn't any view controller). Both of these actors have a mind of their own, and both think they're smarter than the programmer. Typically IB has adjusted the y-origin +20 when a simulated status bar has been turned on, then at run time, the view controller sees the real status bar and adds another +20, producing a 20-pixel gap between the status bar and the top of the content view.
While I can't tell you exactly what you did or didn't do to deserve this error, I can say that it seems to be sensitive to the sequence of actions you take in IB when adding or attempting to re-size the content view, and/or turning the simulated status bar on or off. To complicate matters, whenever IB thinks you don't know what you're doing, it can decide to re-size or move your content view when you aren't looking. This means that you should revisit the frame coordinates in the size inspector after the final save of an xib file.
You have several tools at your disposal to stay one step ahead of the software. Firstly I suggest you choose contrasting background colors for your window and content view(s) so you'll always know which is which and can easily see any offset. Secondly, add some logging someplace where it will run after the content view is loaded; e.g.:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"self.view=%@", self.view);
// uncomment the following only if desperate
// self.view.frame = CGRectMake(0, 20, 320, 460);
// NSLog(@"self.view=%@", self.view);
}
I also recommend setting up the xib window in IB so you always know which object you're inspecting when checking size and attributes. To do this, locate the View Mode switch in the upper-left corner of the xib window (this is the window with the icons, if it's not visible select Window->Document in the IB menu). Set View Mode to the Center position. The xib window should display a two column table with a tree view to the left. You can now see the view hierarchy and select the exact object you want to inspect (you can also modify the hierarchy by dragging in the tree).
Apropos the example code comments, in an emergency you can always force the frame back where it belongs. But I would encourage you to go back into IB and try to fix it there. For example, select the main window, open the Attributes Inspector and turn the simulated status bar on and off with the picker under "Simulated Interface Elements". Look for any change in the y-origin of the content view in the Size Inspector when you add or remove the simulated bar. Can you change the y-origin in the Size Inspector, or is it locked down (grayed out)? If the frame coords are locked, delete the view and see if the frame gets set better when you start with a new view. If you're only dealing with a status bar (no nav, tab, or tool bars), you probably want the content view frame to be 0, 20, 320, 460.
As you can see btw, all of the above assumes the content view will only be in portrait orientation. If landscape is involved, I would still recommend starting with a portrait-only testbed. Once you get the hang of things in portrait, you can move on to landscape.
Hope that helps!
- Ray