views:

22

answers:

1

I'm having difficulty moving an image to another location after the first animation is finished.

the image animates at a point that I've specified, then stops (that works fine). I would then like to move the image to another location and repeat.

here's my code:

-(void) loadTap {

NSArray *imageArray = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"tap1.png"], [UIImage imageNamed:@"tap2.png"], [UIImage imageNamed:@"tap3.png"], [UIImage imageNamed:@"tap4.png"],
nil];

    tapImage.animationImages = imageArray;
    tapImage.animationRepeatCount = 1;

    [imageArray release];

    tapImage.animationDuration = 1;
    tapImage.animationRepeatCount = 20;

    [tapImage startAnimating];
    tapImage.center = CGPointMake(156, 110);

}

thanks for any help.

+1  A: 

In order to move an image, you should enclose the code to move in an animation block:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
tapImage.center = CGPointMake(156, 110);
[UIView commitAnimations];

You can also give a method to execute upon completion of the animation with UIView setAnimationDidStopSelector: method.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animateImages)];
tapImage.center = CGPointMake(156, 110);
[UIView commitAnimations];

//other stuff

-(void)animateImages{
     [tapImage startAnimating];
}
executor21
that helps greatly. thanks so much.
hanumanDev
one quick thing - if, after the completion of the animation, i want to move the image to tapImage.center = CGPointMake(156, 210); and then animate, would that be in a new block?
hanumanDev
Which animation? You don't need an animation block to cycle through the image array, but you do need for any animation of the view in regards to its surroundings (movement, rotation, fading, etc.). So if your sequence of events is: 1. Cycle through images. 2. Move to (156, 110). 3. Cycle again. 4. Move to (156, 210). 5. Cycle again. then, yes, you need a separate animation block at each movement sequence.
executor21
yes, that's what I'm looking for. so, separate animation blocks for each movement sequence. thanks again.
hanumanDev