如何在应用程序中添加动画闪屏

时间:2011-03-07 11:44:39

标签: iphone objective-c

如何在我们的应用程序中添加动画启动画面。

4 个答案:

答案 0 :(得分:4)

您可以使用图像序列,这里是代码:

for(NSInteger i=1;i<=totalImages;i++){
        NSString *strImage = [NSString stringWithFormat:@"Activity_%d",i];
        UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strImage ofType:@"png"]];
        [imageArray addObject:image];
    }
    splashImageView.animationImages = imageArray;
    splashImageView.animationDuration = 0.8;

并且只调用UIImageView的startAnimation和endAnimation方法。

答案 1 :(得分:3)

它很简单......我用它来开始我的应用程序使用splashView.Hope它会帮助你.... 在AppDelegate.m中:

应用程序didFinishLaunchingWithOptions:

UIImage* image=[UIImage imageNamed:@"splash.jpg"];
splashView=[[UIImageView alloc]initWithImage:image];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:@selector(removeSplash) withObject:self afterDelay:2];
[window makeKeyAndVisible];

删除splashView:

-(void)removeSplash{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [splashView removeFromSuperview];
    [UIView commitAnimations];
    [window addSubview:viewController.view];
}

答案 2 :(得分:3)

旧答案:

这还不可能。您无法在启动画面上制作任何动画。但是你可以通过UIViewController课程来实现它,它看起来像启动画面。从项目中删除用户无法看到默认启动画面default.png图像。然后在您的第一个ViewController课程中,您可以使用array of images制作动画,如上所述。然后在viewDidLoad:方法中生成NSTimer,然后根据您保留View。完成NSTimer的时间限制后,导航您的下一个ViewController视图。

修改

我找到了另一种解决方案,让它变得生动。我们可以在webView中显示 .gif 图片,看起来很完美!

NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"animated" ofType: @"gif"];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
[self.webView setUserInteractionEnabled:NO];
[self.webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

将此视图设置为应用的rootView,并在几次延迟后导航您的下一个视图。 请记住使其userIntractionEnabled:为false,即用户无法滚动它。

完整说明请参见此处Animated Splash Screen in iPhone

答案 3 :(得分:2)

我是通过创建图像数组来实现的,因为gif不支持格式

只需添加动画片段的图像帧,例如:{Splashbackground1,Splashbackground2,Splashbackground3是图像序列}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    // create the view that will execute our animation for elephant
    CGRect splashscreenmovieclipframe = CGRectMake(0.0f,0.0f,480.0f, 320.0f); //set co-ordinate here i use full screen
    splashscreenmovieclip = [[UIImageView alloc] initWithFrame:splashscreenmovieclipframe];

    // load all the frames of our animation
    splashscreenmovieclip.animationImages = [NSArray arrayWithObjects:   
                                    [UIImage imageNamed:@"Splashbackground.png"],
                                             [UIImage imageNamed:@"Splashbackground1.png"],
                                             [UIImage imageNamed:@"Splashbackground2.png"],
                                             [UIImage imageNamed:@"Splashbackground3.png"],
                                             nil];

    // all frames will execute in 1.75 seconds
    splashscreenmovieclip.animationDuration =7;
    // repeat the annimation forever
    splashscreenmovieclip.animationRepeatCount = 0;
    // start animating
    [splashscreenmovieclip startAnimating];
    // add the animation view to the main window
    [self.view addSubview:splashscreenmovieclip];

    [NSTimer scheduledTimerWithTimeInterval:7.0f target:self selector:@selector(Gotomainmenuview:) userInfo:nil repeats:NO];

    [super viewDidLoad];
}


- (void)Gotomainmenuview:(NSTimer *)theTimer 
{
    // write your code here for counter update 
    [splashscreenmovieclip removeFromSuperview];
    newclasstojump *mmvc=[[newclasstojump alloc]initWithNibName:@"newclasstojump" bundle:nil];
    [self.view addSubview:mmvc.view];
}