简体   繁体   中英

Splash screen iOS only shown on simulator and at wrong size

When I use the code mentioned below, I get the desired splash screen with fade out on the iPhone simulator, but the picture seems to be zoomed with factor 2: I only get the upper left quarter of my initial picture (= launch image), zoomed to full screen. The launch image itself is shown in correct size at startup, before the splash screen kicks in.

Code is entered in didFinishLaunchingWithOptions in AppDelegate.

// Splash screen
    UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"IMG_1357.png"]];
    [[navigationController view] addSubview:imageView];
    [[navigationController view] bringSubviewToFront:imageView];

    // as usual
    [self.window makeKeyAndVisible];

    //now fade out splash image
    [UIView transitionWithView:self.window duration:4.0f options:UIViewAnimationOptionTransitionNone animations:^(void){imageView.alpha=0.0f;} completion:^(BOOL finished){[imageView removeFromSuperview];}];

Furthermore the splash screen doesn't seem to appear on the device (iPhone 4S (Retina) with iOS 6.0), only on the simulator: when run on iPhone, it only displays the launch image.

What could be the cause and solution to both issues? Thanks in advance!

  1. Setup frame for imageView, otherwise it has the same sizes as an image
  2. Setup correct contentMode
  3. Try to use self.window, instead of [navigationController view]

Example:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMG_1357.png"]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = self.window.bounds;
[self.window addSubview:imageView];
[imageView release];

[self.window makeKeyAndVisible];

//now fade out splash image
[UIView transitionWithView:self.window
                  duration:4.0f
                   options:UIViewAnimationOptionTransitionNone
                animations:^(void) {
                    imageView.alpha = 0.0f;
                }
                completion:^(BOOL finished ){
                    [imageView removeFromSuperview];
                }];

To add a 1 second pause before the fade out:

int64_t delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [UIView transitionWithView:self.window
                      duration:4.0f
                       options:UIViewAnimationOptionTransitionNone
                    animations:^(void) {
                        imageView.alpha=0.0f;
                    }
                    completion:^(BOOL finished ){
                        [imageView removeFromSuperview];
                    }];
});

or

[self performSelector:@selector(_hideSplash:) withObject:imageView afterDelay:1.0];

- (void) _hideSplash:(UIView *)view
{
    [UIView transitionWithView:self.window
                      duration:4.0f
                       options:UIViewAnimationOptionTransitionNone
                    animations:^(void) {
                        view.alpha=0.0f;
                    }
                    completion:^(BOOL finished ){
                        [view removeFromSuperview];
                    }];    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM