Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using the following code to move a UIImageView:

shootImg.image = [UIImage imageNamed:@"Projectile Left 1.png"];
[UIView beginAnimations:nil context:nil];
shootImg.center = CGPointMake(shootImg.center.x+1000, shootImg.center.y);
[UIView commitAnimations];

This works but what I want to do is after [UIView CommitAnimations]; I want to set the location of shootImg using CGPointMake. If I just put it after commitAnimations then the animation doesn't fully complete. Any suggestions? I'm not using any frameworks like cocos2d and if you need to see any more code just ask.

share|improve this question
add comment

1 Answer

You could add inside the [UIView beginAnimations:nil context:nil]; and [UIView commitAnimations]; add the following line: [UIView setAnimationDelegate:self]; and create this methods on your class: setAnimationWillStartSelector: and setAnimationDidStopSelector:

so your code will be like this:

shootImg.image = [UIImage imageNamed:@"Projectile Left 1.png"];
[UIView beginAnimations:nil context:nil];
shootImg.center = CGPointMake(shootImg.center.x+1000, shootImg.center.y);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

and on your class this methods:

+ (void)setAnimationDidStopSelector:(SEL)selector
+ (void)setAnimationWillStartSelector:(SEL)selector

if you like to see more i recommend the documentation for UIView here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.