Unix
Unix

Reputation: 31

Object-c How to animate different set of images in different duration time one after the other (iphone)

i need to animate 10 sets of images ,(10 arrays of images) one after another each set will animate in different duration. i tried to do that with UIImageView like this :

[myImageView1 setAnimationImages:imagesSet1];
[myImageView1 setAnimationRepeatCount:0];
[myImageView1 setAnimationDuration:2];
[myImageView1 startAnimation];


[myImageView1 setAnimationImages:imagesSet2];
[myImageView1 setAnimationRepeatCount:0];
[myImageView1 setAnimationDuration:5];
[myImageView1 startAnimation];

but this not works,it shows the last images.

Upvotes: 2

Views: 2244

Answers (4)

Vishal Vaghasiya
Vishal Vaghasiya

Reputation: 305

Try This Code, Much More Easy, So use it n Enjoy

animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];

animatedImageView.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"1.png"],
                                     [UIImage imageNamed:@"2.png"],
                                     [UIImage imageNamed:@"3.png"],
                                     [UIImage imageNamed:@"4.png"],
                                     [UIImage imageNamed:@"5.png"],
                                     [UIImage imageNamed:@"6.png"],nil];
animatedImageView.animationDuration = 20.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];

Upvotes: 2

banu
banu

Reputation: 787

Try this code:

 NSArray *array1=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballImg1.png"],[UIImage imageNamed:@"ballImg3.png"],[UIImage imageNamed:@"ballImg4.png"],[UIImage imageNamed:@"ballImg5.png"],nil];

 NSArray *array2=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballAniImg1.png"],[UIImage imageNamed:@"ballAniImg3.png"],[UIImage imageNamed:@"ballAniImg4.png"],[UIImage imageNamed:@"ballAniImg5.png"],nil];

 NSArray *array3=[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"ballRotImg1.png"],[UIImage imageNamed:@"ballRotImg3.png"],[UIImage imageNamed:@"ballRotImg4.png"],[UIImage imageNamed:@"ballRotImg5.png"],nil];

array4=[[NSArray alloc] initWithObjects:array1,array2,array3,nil];

 i1=0;   
 [self performSelector:@selector(animation1:) withObject:[NSNumber numberWithFloat:2.0] afterDelay:0];
 i=0;



 -(void)animation1:(NSNumber*)k
{
if(i1<[array4 count])
{
int m1=[k floatValue];
NSArray *arr1= [array4 objectAtIndex:i1];
myImageView1.animationImages=arr1;
myImageView1.animationDuration=m1;
myImageView1.animationRepeatCount=1;
[myImageView1 startAnimating];
i1++;
    [self performSelector:@selector(animation1:) withObject:[NSNumber numberWithFloat:2.0] afterDelay:3.0];

}
}

Upvotes: 3

Aravindhan
Aravindhan

Reputation: 15628

    NSMutableArray *imageArray = [[NSMutableArray alloc] init];

    for (int i = 0; i < 6; i++)
    {
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"ball%d.png", i]]];
        UIImageView *animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
        animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
        animatedImages.animationDuration = 1.0;
        animatedImages.animationRepeatCount = 0;
        [animatedImages startAnimating];
        [myview addSubview:animatedImages];  
        [animatedImages release];

     }

Upvotes: 0

Mathieu Hausherr
Mathieu Hausherr

Reputation: 3485

Try to use blocks

-(void)showImage1 {
    [UIView animateWithDuration:2.0
                          delay:0.0 
                        options:UIViewAnimationOptionTransitionFlipFromLeft 
                     animations:^{
                                     [myImageView1 setImage:image1];
                                 };
                     completion:^(BOOL finished){
                                       [self showImage2];
                                }];
}

-(void)showImage2 {
    [UIView animateWithDuration:5.0
                          delay:0.0 
                        options:UIViewAnimationOptionTransitionFlipFromLeft 
                     animations:^{
                                     [myImageView1 setImage:image2];
                                 };
                     completion:^(BOOL finished){
                                       ...
                                }];
}

Upvotes: 1

Related Questions