Reputation: 9219
I want to display series of images one by one when the app loads. Basically I want to create some kind of animation by loading these images sequentially.
I know it is possible. I have seen many apps which does that.
Can you please let me know how can this be done?
Thanks!
Upvotes: 0
Views: 824
Reputation: 655
-(void)viewDidLoad
{
[super viewDidLoad];
animationImageNumber=0;
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self
selector:@selector(startAnimation) userInfo:nil repeats:YES];
}
-(void)startAnimation
{
if (animationImageNumber<9) {
animationImageNumber++;
}
else
{
animationImageNumber=0;
}
[self animationImageChange:[NSString stringWithFormat:@"%d",animationImageNumber]];
}
-(void)animationImageChange:(NSString *)imageName
{
NSString* imagePath=[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
[backgroundImage setImage:[UIImage imageWithContentsOfFile:imagePath]];
}
Upvotes: 0
Reputation: 6164
Yes, This is possible,for displaying series of screen after the splash screen and before the first view of app appears .
for that Add below code to your AppDelegate.m file
`- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// create the view that will execute our animation
[self.window addSubview:firstViewController.view];
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 480)];
// load all the frames of our animation
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"img1.png"],
[UIImage imageNamed:@"img2.png"],
[UIImage imageNamed:@"img3.png"],
[UIImage imageNamed:@"img4.png"],
[UIImage imageNamed:@"img5.png"],
nil];
imageView.animationDuration = 10.0;
// repeat the annimation once
imageView.animationRepeatCount = 1;
[imageView startAnimating];
// add the animation view to the main window
[window insertSubview:imageView aboveSubview:firstViewController.view];
[imageView release];
}
[window setNeedsLayout];
[window makeKeyAndVisible];
return YES;
} `
Upvotes: 0
Reputation: 2838
Take a look at UIImageView's animationImages property. You can assign an NSArray of images to this property. Below is an example but there may be typos as i'm typing this from memory.
-(void)viewDidLoad
{
UIImageView *flower = [[UIImageView alloc] init];
flower.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"bloom1.png"],[UIImage imageNamed:@"bloom2.png"], [UIImage imageNamed:@"bloom3.png"], nil]; //add more images as necessary
flower.animationDuration = 1.00;
flower.animationRepeatCount = 1;
[flower startAnimating];
[self.view addSubview:flower];
[flower release]
}
Upvotes: 1