开发者

iPad Layout different only on launch

Ok I have an interesting issue on an iPad application I am developing.

When the app launches in portrait mode the layout works as expected. I rotate the iPad and the rotation works fine.

When the application launches in landscape mode there is additional white space appearing and the layout does not work as expected. But when I rotate the application to portrait it rotates just fine. It also lays out fine when I rotate it back to landscape.

What could be causing this problem? The view controller in question is a view controller that contains a UINavigationController (I had to add in a head开发者_如何学Cer). I wonder if it is something with UINavigationController.


Your view is expecting Portrait mode upon launch. In your view Controller, you need to let it know to look for orientation, and load the corresponding view.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
        (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){

        self.view = landscape;

    }else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || 
              (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){

        self.view = portrait;
    }

    return YES;
}


Ok so what was strange in my application is that the layout would become correct when the tab controller switched tabs back to the view that was being funky. So, I added a hack in order to switch between the tabs before the makeKeyAndVisible of the main window.

I did try your suggestion WrightsCS. The real reason it didn't work is because I'm loading UINavigationController's view in the sub view of the page, so I didn't really have control of the layout that was messing up. The top bar of the navigation controller was loading a little lower than it should have been.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜