iPad 布局仅在发布时有所不同

发布于 2024-10-07 14:40:29 字数 276 浏览 6 评论 0原文

好吧,我正在开发的 iPad 应用程序有一个有趣的问题。

当应用程序以纵向模式启动时,布局将按预期工作。我旋转 iPad,旋转效果很好。

当应用程序以横向模式启动时,会出现额外的空白,并且布局无法按预期工作。但是当我将应用程序旋转为纵向时,它旋转得很好。当我将其旋转回横向时,它的布局也很好。

什么可能导致这个问题?有问题的视图控制器是包含 UINavigationController 的视图控制器(我必须添加标头)。我想知道这是否与 UINavigationController 有关。

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 header). I wonder if it is something with UINavigationController.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┼── 2024-10-14 14:40:29

您的视图在启动时需要纵向模式。在你的视图控制器中,你需要让它知道寻找方向,并加载相应的视图。

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

        self.view = landscape;

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

        self.view = portrait;
    }

    return YES;
}

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;
}
她比我温柔 2024-10-14 14:40:29

好吧,我的应用程序中奇怪的是,当选项卡控制器将选项卡切换回时髦的视图时,布局会变得正确。因此,我添加了一个 hack,以便在主窗口的 makeKeyAndVisible 之前的选项卡之间进行切换。

我确实尝试过你的建议 WrightsCS。它不起作用的真正原因是因为我在页面的子视图中加载 UINavigationController 的视图,所以我无法真正控制混乱的布局。导航控制器顶部栏的加载速度比应有的要低一些。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文