Search code examples
iphonelayoutios4

iPhone View Shifted When Run


I'm very new to iPhone development so please bear with me. I'm following the tutorial from Apple for creating a "Hello World" application (found here). The problem is (and this is a problem I've had with all tutorials I've attempted to follow) that when I create the application with a subview inside the window, the subview itself is shifted up approximately 20px.

This picture is taken from Apple and shows what the application should look like: Image from Apple example http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhone101/Art/viewBackgroundColor.jpg

It looks as it should in the interface builder, but when I run it on the simulator or on a device, it looks like this:

My simulator

Has anybody experienced this before/have any suggestions? I'm not trying to do anything complicated and I have a feeling it's just something simple.

The code for my application:didFinishLaunchingWithOptions method is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    MyViewController *mvc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
    self.myViewController = mvc;
    [mvc release];

    [window addSubview:[self.myViewController view]];
    [window makeKeyAndVisible];

    return YES;
}

And MyViewController is nothing more than what is created by Xcode when you create the file.

Any thoughts?

Thanks in advance!

Edit Is there a way to simply shift the view down? I'm thinking that maybe the view is the correct size, it's simply shifted up behind the status bar.

Also, just to summarize my comments below, all of my settings are the same as those in the Apple documentation. Additionally, my view is set to 460px high.


Solution

  • Check the size of the view -- it should be 320 by 480. Views (obviously) don't have to be full screen, and thus IB makes them resizable with the resize-grip-thing in the lower right corner, which you may have accidentally used.