iPad app landscape启动带有纵向尺寸的根视图控制器

run*_*mad 3 ipad uiinterfaceorientation ios

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

在我的App Delegate中,我将一个RootViewController添加到窗口的rootViewController中.

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我根据视图控制器视图的尺寸创建和添加子视图时,我无法获得应用程序的正确尺寸.

如果我为我的视图控制器输出self.view.frame {{0, 0}, {768, 1024}},我会得到{1024,768}.如果我不能在什么时候尺寸正确,那么我可以用它们来创建我的观点?

对不起,如果这被问了十亿次,我浏览了很多SO问题,但没有解决我的问题.

小智 5

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

我正在创建一个适用于所有方向的iPad应用程序,但只有纵向方向在我的根UIViewController中正确设置.为了在横向上正确地进行视图布局,我必须确保所有子视图上的自动调整遮罩都设置为允许视图在显示给用户之前调整为幕后景观.

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

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

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