开发者

UIVIewController wrong position before rotate

I have the starter point of my application this window (white background):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    mainScreen = [[MainScreenController alloc] initWithNibName:@"MainScreenController" bundle:[NSBundle mainBundle]];

    // add it to the main window
    [window  addSubview:[mainScreen view]];

    // show view
    [window makeKeyAndVisible];

    NSLog(@"started");

    return YES;
}

And MainScreenController is an UIViewController with (blackBackground) created by the Interface Builder.

The application executes perfectly but the first time, the black view is moved up like the height of the status iphone pannel (leaving white rectangle at the bottom).

If I rotate the iPhone twice, the view is perfectly positioned in the right place, filling all the screen with the 开发者_如何学Goblack background.

Any idea?

Thanks!


Check your MainScreenController settings in IB. You should select a simulated status bar element (cmd-1) so that the view is positioned below the status bar initially.

EDIT - Why are you calling the initWithNibName in your delegate here? Most of the app templates I've used had the main view nib initialized by the OS and you use IB and set an IBOutlet in the main VC interface. You probably have an initial frame origin of {0,0} after calling initWithNibName. Add these lines after your initWithNibName call to verify this:

NSLog(@"mainscreen frame=%@", NSStringFromCGRect(mainscreen.view.frame));

CGRect frame = mainscreen.view.frame;
frame.origin.y = 20;  // move below status bar
mainscreen.view.frame = frame;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜