Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade out Launch Image on 4 Inch iPhone screen

On launch, I am fading from my launch image to the application's interface. To achieve this, I am adding a UIImageView with "Default.png" and animating its alpha just before makeKeyAndVisible.

Should Default.png always return the device-specific (or resolution-specific) version of the launch image? Or should I be checking the screen's bounds and scale to pick the right one for the retina vs non-retina and 3.5 vs 4 inch screens?

I expected Default.png to behave much like other image resources - use the @2x version when supported (and the -568h version on the iPhone 5). But my experimentation in the simulator leads me to believe otherwise. Running the 4 inch simulator, the 3.5 inch image is used. This results in a splash image that does not extend to the bottom of the screen. The screenshot below shows the transition mid-animation.

enter image description here

Unfortunately I don't have each device so was unable to confirm if this is just a quirk of the simulator.

In short, I want to be sure that the retina image is used on retina devices, and the 4 inch image is used on 4 inch devices.

like image 947
Ben Packard Avatar asked Dec 16 '22 18:12

Ben Packard


1 Answers

This is my code

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

    [self.window makeKeyAndVisible];

    [self _startLaunchAnimation];

    return YES;
}

- (void)_launchAnimation {
    CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
    UIImageView *launchImageView = (UIImageView*)[self.window viewWithTag:1000];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone
                           forView:self.window
                             cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    [launchImageView setAlpha:0.0];
    [launchImageView setFrame:CGRectMake(-60.0f, 0.0f, 320.0f, screenHeight)];
    [UIView commitAnimations];
}

- (void)_startLaunchAnimation {
    CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
    NSString *imageName = nil;
    if (screenHeight == 568.0f) {
        imageName = @"Default-568h.png";
    } else {
        imageName = @"Default.png";
    }

    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *launchImageView = [[UIImageView alloc] initWithImage:image];
    [launchImageView setTag:1000];
    [self.window addSubview:launchImageView];

    [NSTimer scheduledTimerWithTimeInterval:2.0
                                     target:self
                                   selector:@selector(_launchAnimation)
                                   userInfo:nil
                                    repeats:NO];
}
like image 61
agassi_yzh Avatar answered Dec 24 '22 13:12

agassi_yzh