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

时间:2012-07-03 17:45:20

标签: iphone ios ipad default.png

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

5 个答案:

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

答案 1 :(得分: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上运行,您将需要检查该情况并添加正确的默认图像。

答案 2 :(得分:0)

有人在cocoacontrols.com上对其进行了控制

以下是其中的链接:http://cocoacontrols.com/platforms/ios/controls/launchimagetransition

答案 3 :(得分:0)

扩展rooster117的答案,您需要在解除“启动画面”视图控制器之前正确加载您的最终“登陆位置”,即您希望用户实际与之交互的视图控制器。这对于从网络加载数据的应用程序非常重要。

答案 4 :(得分:0)

我好像用ios7这样做了,认为它也适用于6?

https://stackoverflow.com/a/19377199/1734878