为什么我的ModalView以纵向模式显示?

时间:2011-11-09 19:47:54

标签: ios xcode modalviewcontroller

希望有人可以在这里指出我的Splash屏幕出错了。问题是屏幕以纵向模式显示,而不是横向显示...

- (void)showSplash
{    
UIView *modelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024 , 748)];

UIViewController *modalViewController = [[UIViewController alloc] init];
[modelView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage     imageNamed:@"Splash.png"]]];

modalViewController.view = modelView; 

[self presentModalViewController:modalViewController animated:NO];


[self performSelector:@selector(hideSplash) withObject:nil afterDelay:5.0];

}

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

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

看起来你正在为iPad编写应用程序。如果是这样,你必须同时支持横向和纵向,否则Apple将拒绝它。我建议你应该使用两个不同的图像。图像规格如下:

  1. Default-Landscape.png(1004 * 768)
  2. Default-Portrait.png(748 * 1024)
  3. (我假设您正在显示状态栏,如果不向图像的高度添加20像素)

    就是这样,创建这些图像并将其添加到您的项目中。你很高兴。无需再编写任何其他代码..

    你做到了

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

答案 1 :(得分:0)

您不应该依赖代码中的函数来显示启动画面。只需将它们定义为Sumit Lonkar先前的答案。

如果您在代码中执行此操作,我相信在应用程序开始时,方向始终被视为纵向,然后会触发到实际方向的转​​换。这解释了为什么您的代码首先显示为纵向,并且很可能代码中没有其他任何内容可以处理旋转。此外,启动画面的目的是在应用程序加载时显示某些内容,因此如果您将其放入代码中,则会失去目的。

通过Apple方式,您可以将其留给另一个在查看代码之前运行的Apple流程,并且它可以正常工作。

关于支持的方向,我在iPad上有一些仅支持横向的应用程序(例如TapZoo),所以它应该适用于Apple。

相关问题