【问题标题】:How to use Default Splash Screen for Universal application?如何为通用应用程序使用默认启动画面?
【发布时间】:2012-06-01 17:08:26
【问题描述】:

我有一个通用应用程序。在此应用程序中,我将介绍图像设置为启动画面。对于 iPhone,我需要设置不同的图像作为启动屏幕,而对于 iPad,我需要设置不同的图像。当我使用下面的代码时,它适用于 iphone 但不适用于 ipad。这是我的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   [self copyDatabaseIfNeeded];
   [window addSubview:navigationController.view];
   [window makeKeyAndVisible];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
    splashViewBg.image = [UIImage imageNamed:@"jamil.png"];
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill;
    [window addSubview:splashViewBg];

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
    splashView.image = [UIImage imageNamed:@"jamil.png"];
    //splashView.contentMode = UIViewContentModeScaleAspectFill;
    splashView.alpha = 0.0f;
}
else
{
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashViewBg.image = [UIImage imageNamed:@"defualt.png"];
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill;
    [window addSubview:splashViewBg];

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"defualt.png"];
    //splashView.contentMode = UIViewContentModeScaleAspectFill;
    splashView.alpha = 0.0f;
}

[UIView beginAnimations:@"show" context:NULL];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
splashView.alpha = 1.0f;
[UIView commitAnimations];

[self performSelector:@selector(removeSplash) withObject:nil afterDelay:2.0];

[self performSelector:@selector(removeSplashBg) withObject:nil afterDelay:3.5];

return YES;
 }

 - (void) removeSplash {
   [UIView beginAnimations:@"hide" context:NULL];
   [UIView setAnimationDuration:1.0f];
   [UIView setAnimationCurve:UIViewAnimationCurveLinear];
   [UIView setAnimationDelegate:self];
   splashView.alpha = 0.0f;
  [UIView commitAnimations];
}

  - (void) removeSplashBg {
      [splashView removeFromSuperview];
      [splashViewBg removeFromSuperview];
}

【问题讨论】:

  • 您是否尝试过调试,无论条件是否为真?因为似乎它总是会去别的地方。
  • @rishi 是的,我在使用 ipad 时使用断点,我的控件运行 if 部分。
  • 图片是否存在,是否已添加到您的项目中,名称是否正确?在断点之后检查图像是否有值。这是最有可能出错的地方。
  • 你见过这个吗? stackoverflow.com/a/2634942/1344459希望对你有所帮助。
  • @jrturton 图像存在,它也获得了价值,这就是为什么我是伤员?我仔细检查了你提到的每一件事,但仍然没有得到 ipad 的图像。

标签: iphone ios ipad splash-screen beginanimations


【解决方案1】:

我知道这并不能直接回答您的问题,但 Apple 的指导方针明确规定不要使用启动画面图像。强烈建议不要这样做,并且可能会给您的用户带来非常糟糕、不一致的体验。如果您必须在应用程序加载时显示屏幕,则无需编写任何代码即可。只需将图像命名为 Default.png 和 Default@2x.png。它们将自动加载并显示为闪屏。请参阅documentation for "Launch Images"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-12
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    相关资源
    最近更新 更多