0

当我使用下面提到的代码时,我在 iPhone 模拟器上获得了所需的闪屏,但图片似乎放大了 2 倍:我只得到初始图片的左上角四分之一(= 启动图像),放大到全屏。在启动画面启动之前,启动图像本身会以正确的大小显示。

代码在 AppDelegate 中的 didFinishLaunchingWithOptions 中输入。

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

此外,启动画面似乎没有出现在设备上(iPhone 4S(Retina)和 iOS 6.0),只出现在模拟器上:在 iPhone 上运行时,它只显示启动图像。

这两个问题的原因和解决方案可能是什么?提前致谢!

4

1 回答 1

2
  1. imageView 的设置框架,否则它与图像具有相同的大小
  2. 设置正确的 contentMode
  3. 尝试使用 self.window,而不是 [navigationController 视图]

例子:

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

要在淡出之前添加 1 秒暂停:

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

或者

[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];
                    }];    
}
于 2012-11-18T23:57:03.017 回答