hanumanDev
hanumanDev

Reputation: 6614

iphone - moving a UIImageView

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.

Upvotes: 1

Views: 7018

Answers (1)

executor21
executor21

Reputation: 4596

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];
}

Upvotes: 6

Related Questions