iOS 7启动图像(启动画面)淡出

问题描述 投票:40回答:7

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

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

编辑答案:

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

animation splash-screen ios7 fadeout
7个回答
6
投票

我已经设法在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+测试)

    -(NSString*)getLaunchImageName
{

    NSArray* images= @[@"LaunchImage.png",
                       @"[email protected]",
                       @"[email protected]",
                       @"[email protected]",
                       @"[email protected]",
                       @"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",
                       @"[email protected]",
                       @"[email protected]",
                       @"[email protected]",
                       ];

    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;
}

4
投票

在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];
    });
}

3
投票

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

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

相反,我把它移到了方法

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

现在它不再“褪色”了。请注意遗嘱而不是遗嘱。此方法在iOS6及更高版本上可用,因此如果您希望您的应用程序与iOS5.x兼容并且较低,则可以对<__ IPHONE_6_0进行预处理器版本检查并使用“didFinishLaunching”方法,因为它不是甚至是一个问题。


2
投票

如果这确实是您的代码,您可能在图像名称中输入了拼写错误。 (如果没有,请告诉我们“不工作”的含义。)

此外,启动画面通常不会出现每个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;
}

1
投票

我只是想确认Patrick的答案,因为它与Cocos2D应用程序有关,并且还添加了一些细节。

如果你在6.1模拟器和7.x模拟器之间切换,行为确实很容易看到 - 第一个是快速切换(可能是黑色闪光,出于同样的原因),而7.x模拟器做得很慢并且烦人的淡化为黑色,然后是你的Cocos2D场景的眨眼。

如果您不想修改或子类化CCDirector的东西,您也可以使用相同的代码来修改AppDelegate。在我们的例子中,它非常简单:

  1. 在appDidFinishLaunching中......我们等到创建了glView,然后将UIImage添加为子视图;
  2. 然后我们创建一个“postDidFinish ...”例程,并在0.1f秒左右后执行Selector调用它。然后,您可以使用相同的代码删除FromSubview。

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


0
投票

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


-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.