启动应用后,如何从Default.png淡入?

3

启动iOS应用程序时,屏幕从Default.png跳转到界面。对于当前的项目,我想从Default.png淡入到应用程序的界面。有没有好的方法可以做到这一点?


1
如果使用故事板,您可以使用自定义segue创建启动画面。 - Richard J. Ross III
5个回答

4
我借鉴了rooster117和runmad的答案,并得出了以下内容。
将UIImageView添加到第一个UIViewController的属性中:
@interface DDViewController : UIViewController {
   ...
    UIImageView *coverImageView;
}

...

@property (nonatomic, retain) UIImageView *coverImageView;

接下来,针对iPad应用的“主屏幕”,我调用以下代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    ...

    coverImageView = [[UIImageView alloc] init];
}

-(void)viewWillAppear:(BOOL)animated {
    UIImage *defaultImage;   
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
        NSLog(@"Landscape!");
        defaultImage = [UIImage imageNamed:@"Default-Landscape.png"];
    } else {
        NSLog(@"Portrait!");
        defaultImage = [UIImage imageNamed:@"Default-Portrait.png"];
    }

    coverImageView = [[UIImageView alloc] initWithImage:defaultImage];
    [self.view addSubview:coverImageView];

}

-(void)viewDidAppear:(BOOL)animated {
    //Remove the coverview with an animation
    [UIView animateWithDuration:1.0f animations:^(void) {
        [self.coverImageView setAlpha:0.0];
    } completion:^(BOOL finished){
        [coverImageView removeFromSuperview];
    }];
}

2

这并不难做到。我通过创建一个带有默认图片的图像视图,并将其动画化来实现。类似这样(将其放入第一个视图控制器的viewDidLoad中):

_coverImage = [UIImage imageNamed:@"Default.png"];
}

[self.view addSubview:_coverImage];

[UIView beginAnimations:@"FadeOutCover" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(removeAndDeleteCover)];

[_coverImage setAlpha:0.0f];

[UIView commitAnimations];

然后实现 removeAndDeleteCover 并执行:
[_coverImage removeFromSuperview];

希望这能帮助到你。如果你需要它在iPad上作为通用应用程序运行,你需要检查并添加正确的默认图片。请保留HTML标签。

虽然这段代码是正确的,但我建议使用UIView动画块,它更简单、更清晰易懂。 - runmad
我同意,但我试图传达需要完成的内容。 - rooster117
我找到了一种使用UIView动画块的方法,然后挖掘了一下如何适应设备的方向。我的答案在上面。 - bryanjclark

0

0

0

在rooster117的答案基础上,您需要在关闭“启动画面”视图控制器之前正确加载最终的“着陆点”,也就是您希望用户实际交互的视图控制器。这对于从网络加载数据的应用程序非常重要。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接