1

My program keeps crashing:

-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve    x:(CGFloat)x y:(CGFloat)y key:(NSString *)key
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:)];

CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView commitAnimations];
}

This gets called, and when finished i want it to call the method bellow:

-(void)animationDidStop:(NSString *)key
{
if (key == @"burn") {
    //The burn card has been moved and stopped. Ready for the next.
    [self annPlayerRight];
}

}

What am i doing wrong?

JH95
  • 489
  • 1
  • 7
  • 24
  • possible duplicate of [Apple rejected app because of animationDidStop:finished:context: is a non-public api](http://stackoverflow.com/questions/3455604/apple-rejected-app-because-of-animationdidstopfinishedcontext-is-a-non-public) – trojanfoe Jul 02 '12 at 09:33

2 Answers2

4

Well, yeah because setAnimationDidStopSelector:withObject: method does not exist... UIView's actual method is : + (void)setAnimationDidStopSelector:(SEL)selector

(notice that the withObject: part is missing)

Alladinian
  • 34,483
  • 6
  • 89
  • 91
3

Check Documentation for setAnimationDidStopSelector method.

The message sent to the animation delegate after animations end. The default value is NULL. The selector should be of the form:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context.

So when you call beginAnimations there is parameter context that would be accessible in animationDIdStop method.

Hope this helps.

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
  • I see but i am still confused, so its not possible to send a string as a parameter through: [UIView setAnimationDidStopSelector:@selector(animationDidStop:)]; – JH95 Jul 02 '12 at 09:51
  • Right now no. You can send in beginAnimation through Context only. – Janak Nirmal Jul 02 '12 at 09:53
  • Just asking what is the problem with `[UIView beginAnimations:nil context:NULL];` sending parameter in context here ? – Janak Nirmal Jul 02 '12 at 10:00