gpt4 book ai didi

ios - iPad 应用横向启动具有纵向尺寸的 Root View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:12:46 26 4
gpt4 key购买 nike

我设置了一个新的 iPad 项目,只支持 UIInterfaceOrientationLandscapeRight。

在我的 App Delegate 中,我将 RootViewController 添加到窗口的 rootViewController。

在这个 UIViewController (RootViewController) 中,我有以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

我也试过:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

但是,当我根据 View Controller View 的尺寸创建和添加 subview 时,我无法为我的应用获得正确的尺寸。

如果我为我的 View Controller 输出 self.view.frame,我得到 {{0, 0}, {768, 1024}},但我想要 {1024, 768}。如果我不能,什么时候尺寸是正确的,以便我可以在创建 View 时考虑到这些尺寸?

抱歉,如果这个问题已经被问了十亿次,我已经浏览了很多 SO 问题,但没有解决我的问题。

最佳答案

我遇到了同样的问题,Ash Furrow 上面说的似乎是正确的; viewDidLoad 被调用后设置方向。

我正在创建一个适用于所有方向的 iPad 应用程序,但在我的根 UIViewController 中只有纵向设置正确。为了使 View 在横向上正确布局,我必须确保我所有 subview 上的自动调整大小掩码都设置为允许 View 在显示给用户之前在幕后调整为横向。

例如,我有一个与 UIViewController 的 UIView 大小相同的 UIImageView。为了让它在旋转到横向时正确调整:

UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];    
backgroundImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
[self.view addSubview:backgroundImageView];

现在可以在 viewDidLoad 方法中将 UIViewController 配置为纵向,并在显示给用户之前很好地旋转到纵向。

关于ios - iPad 应用横向启动具有纵向尺寸的 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9810390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com