【问题标题】:iOS 7 launch image (splash screen) fades outiOS 7 启动图像(启动画面)淡出
【发布时间】:2013-08-24 22:31:01
【问题描述】:

在 iOS 7 上,启动图像会在应用加载时淡出而不是立即消失。

是否有任何设置可以防止此启动图像淡出动画? 我需要它立即消失,就像在 iOS 6 和更早版本中一样。

编辑答案:

是的,可以将启动图像作为 UIImageView 添加到顶部窗口,并在启动淡入淡出动画完成后将其隐藏。但这会导致 0.4 秒的延迟,我试图避免。

【问题讨论】:

  • 好吧,不要指望使用会破坏 NDA,最好的办法是在开发者论坛上问这个问题
  • 大约一个月前有人问过,但到目前为止没有任何回应。信不信由你,Apple Dev Forums 是讨论 iOS 开发最没用的地方。
  • 虽然这是真的,但人们可能不想在这里谈论它来破坏 NDA。
  • 保密协议已经结束——有人有答案吗?
  • 你从哪里得到“0.4秒”这个数字?

标签: animation splash-screen ios7 fadeout


【解决方案1】:

我已经设法在 AppController 中做到了。只需在创建 glView 后立即放置此代码

    UIImage* image = [UIImage imageNamed:[self getLaunchImageName]];
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)])
{
    float screenScale = [[UIScreen mainScreen] scale];
    if (screenScale > 1.)
        image = [UIImage imageWithCGImage:image.CGImage scale:screenScale orientation:image.imageOrientation];
}
UIImageView *splashView = [[UIImageView alloc] initWithImage:image];
[viewController.view addSubview:splashView];
[splashView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.1f];

这很容易。只需获取启动图像并使其在延迟后消失即可。您将需要 getLaunchImage 代码(基于 this comment,未在 iPhone 6 和 6 plus 上测试过)

    -(NSString*)getLaunchImageName
{

    NSArray* images= @[@"LaunchImage.png",
                       @"LaunchImage@2x.png",
                       @"LaunchImage-700@2x.png",
                       @"LaunchImage-568h@2x.png",
                       @"LaunchImage-700-568h@2x.png",
                       @"LaunchImage-700-Portrait@2x~ipad.png",
                       @"LaunchImage-Portrait@2x~ipad.png",
                       @"LaunchImage-700-Portrait~ipad.png",
                       @"LaunchImage-Portrait~ipad.png",
                       @"LaunchImage-Landscape@2x~ipad.png",
                       @"LaunchImage-700-Landscape@2x~ipad.png",
                       @"LaunchImage-Landscape~ipad.png",
                       @"LaunchImage-700-Landscape~ipad.png",
                       @"LaunchImage-800-667h@2x.png",
                       @"LaunchImage-800-Portrait-736h@3x.png",
                       @"LaunchImage-800-Landscape-736h@3x.png",
                       ];

    UIImage *splashImage;

    if ([self isDeviceiPhone])
    {
        if ([self isDeviceiPhone4] && [self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[1]];
            if (splashImage.size.width!=0)
                return images[1];
            else
                return images[2];
        }
        else if ([self isDeviceiPhone5])
        {
            splashImage = [UIImage imageNamed:images[1]];
            if (splashImage.size.width!=0)
                return images[3];
            else
                return images[4];
        }
        else if ([self isDeviceiPhone6])
        {
            splashImage = [UIImage imageNamed:images[1]];
            if (splashImage.size.width!=0)
                return images[13];
            else
                return images[14];
        }
        else
            return images[0]; //Non-retina iPhone
    }
    else if ([[UIDevice currentDevice] orientation]==UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)//iPad Portrait
    {
        if ([self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[5]];
            if (splashImage.size.width!=0)
                return images[5];
            else
                return images[6];
        }
        else
        {
            splashImage = [UIImage imageNamed:images[7]];
            if (splashImage.size.width!=0)
                return images[7];
            else
                return images[8];
        }

    }
    else
    {
        if ([self isDeviceRetina])
        {
            splashImage = [UIImage imageNamed:images[9]];
            if (splashImage.size.width!=0)
                return images[9];
            else
                return images[10];
        }
        else
        {
            splashImage = [UIImage imageNamed:images[11]];
            if (splashImage.size.width!=0)
                return images[11];
            else
                return images[12];
        }
    }
}

-(BOOL)isDeviceiPhone
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return TRUE;
    }

    return FALSE;
}

-(BOOL)isDeviceiPhone4
{
    if ([[UIScreen mainScreen] bounds].size.height==480)
        return TRUE;

    return FALSE;
}


-(BOOL)isDeviceRetina
{
    if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
        ([UIScreen mainScreen].scale == 2.0))        // Retina display
    {
        return TRUE;
    }
    else                                          // non-Retina display
    {
        return FALSE;
    }
}


-(BOOL)isDeviceiPhone5
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[UIScreen mainScreen] bounds].size.height==568)
    {
        return TRUE;
    }
    return FALSE;
}

-(BOOL)isDeviceiPhone6
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[UIScreen mainScreen] bounds].size.height>568)
    {
        return TRUE;
    }
    return FALSE;
}

【讨论】:

  • 啊,好的,抱歉。添加图像时,我没有注意到任何延迟。它是即时的。您可以使用“延迟”参数(但现在是 0.1 秒,而不是 0.4 秒)调整您想要在 UI 前面显示图像的时间
  • Alex R.R.:您的解决方案非常完美!但请考虑根据此版本的 getLaunchImageName 更改您的答案:stackoverflow.com/a/27797958/540639。它看起来更加优雅。
【解决方案2】:

在 iOS 7 中,初始屏幕会从初始图像淡化过渡到您的第一个 UIView。如果该 UIView 看起来与初始屏幕相同,则您看不到淡入淡出。问题是 Cocos2D 的初始视图是纯黑色的。

不幸的是,我发现解决此问题的唯一方法是实际添加一个与初始图像相同的 UIImageView 一秒钟,然后在 Cocos2D 开始绘制后将其删除。

在 CCDirectorIOS(或您的子类)中:

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_WIDESCREEN (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height > 567.0f)
static const NSInteger tempSplashViewTag = 87624;

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    NSString *spriteName = IS_IPAD ? @"Default-Landscape" : IS_WIDESCREEN ? @"Default-568h" : @"Default";
    UIImageView *splashView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:spriteName]];
    splashView.tag = tempSplashViewTag; 
    [self.view addSubview:splashView];

    [self startAnimation];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        UIView *splashView = [self.view viewWithTag:tempSplashViewTag];
        [splashView removeFromSuperview];
    });
}

【讨论】:

  • @erkanyildiz 0.4 秒从什么时候开始?我发现 -[viewDidAppear] 的时间更短。 0.4 秒是相当长的等待时间。
【解决方案3】:

我在使用 Cocos2D-x 开发应用程序并在其中初始化主窗口和 OpenGL 内容时遇到了同样的问题

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

我把它移到了方法中

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

现在它不再“褪色”了。注意 will 而不是 did。但是,此方法在 iOS6 及更高版本上可用,因此如果您希望您的应用与 iOS5.x 及更低版本兼容,您只需对

【讨论】:

  • 谢谢!这也适用于标准视图控制器。
  • cocos2d-x v2.2.5 对我有用,但升级到 3.2 再次失败,我看到黑屏再次消失
  • 是的,这对我不起作用。在 Cocos2d-x 的 v3.9 中仍然淡出。
【解决方案4】:

如果这确实是您的代码,那么您的图像名称可能有错字。 (如果没有,请告诉我们“不工作”是什么意思。)

此外,启动画面通常不会出现在每个 applicationDidBecomeActive: 中。 didFinishLaunchingWithOptions:是您知道自己已启动并且已代表您显示初始屏幕的时间。

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [UIView animateWithDuration:0.2
                          delay:0
                        options: UIViewAnimationCurveEaseIn // change effect here.
                     animations:^{
                        self.window.viewForBaselineLayout.alpha = 0; // and at this alpha
                     }
                     completion:^(BOOL finished){
                     }];

    return YES;
}

【讨论】:

    【解决方案5】:

    我只是想确认 Patrick 的回答,因为它与 Cocos2D 应用程序有关,并添加更多细节。

    如果您在 6.1 模拟器和 7.x 模拟器之间切换,该行为确实很容易看到 - 第一个是即时切换(出于同样的原因,可能会闪烁黑色),而 7.x 模拟器会缓慢而烦人的渐变为黑色,然后是 Cocos2D 场景的闪烁。

    如果您不想修改或继承 CCDirector 的东西,您也可以使用他的相同代码来修改您的 AppDelegate。在我们的例子中,很简单:

    1. 在 appDidFinishLaunching ... 我们等到 glView 已创建,然后将 UIImage 作为子视图添加到它;
    2. 然后我们创建一个“postDidFinish...”例程,并在 0.1f 秒左右后调用 performSelector。然后,您可以使用他的相同代码 removeFromSubview。

    它不像添加到 CCDirector 类那样优雅和不可见,但作为快速修复很容易进入!

    【讨论】:

      【解决方案6】:

      从 iOS 12 开始,仍然无法禁用闪屏淡出动画。

      【讨论】:

        【解决方案7】:

        我怀疑这里还有更多事情要做。在应用程序周期开始时放置一些日志记录语句,因为在调用 App Delegate 方法时会出现启动屏幕,因此请在此处登录并在必要时使用 Instruments 以查看启动时发生的情况。还可以尝试在重新启动之前结束应用程序上的多任务,看看是否有区别,还可以尝试一个新的空应用程序,看看体验是否相同。您没有说明应用程序在启动时会做什么,但是您是否编写了任何动画来影响启动时的淡入或淡出?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-12-30
          • 1970-01-01
          • 1970-01-01
          • 2013-04-08
          • 2020-08-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多