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

时间:2013-08-22 09:17:43

标签: animation splash-screen ios7 fadeout

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

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

编辑答案:

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

7 个答案:

答案 0 :(得分: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",
                       @"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;
}

答案 1 :(得分: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];
    });
}

答案 2 :(得分: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”方法,因为它甚至不是问题。

答案 3 :(得分: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;
}

答案 4 :(得分:1)

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

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

如果您不想修改或继承CCDirector的内容,您也可以使用相同的代码修改AppDelegate。在我们的例子中,它非常简单:

  1. 在appDidFinishLaunching中......我们等到创建了glView,然后将UIImage添加为子视图;
  2. 然后我们创建一个" postDidFinish ......"例程和performSelector在0.1f秒左右后调用它。然后,您可以使用相同的代码删除.FromSubview。
  3. 它不像添加到CCDirector类那样优雅和不可见,但它很容易作为快速修复进入!

答案 5 :(得分:0)

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

答案 6 :(得分:-1)

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

相关问题