rahulbsb
rahulbsb

Reputation: 115

animationDidStop: finished: delegate method not getting called

i want to start a new animation routine as soon as the previous one completes. When the previous does complete however, the new one does not get triggered since the delegate method is not being called. I have delegated a view controller to handle the animations of a button's CALayer. The 'buttonSlide' is the previous animation while 'buttonFade' is the new one. Here's the code snippet:-

-(void)viewWillAppear:(BOOL)animated{

NSLog(@"TimeView appearing...");
[super viewWillAppear:animated];
[self pressButton:nil]; // Shows current time as soon as TimeView appears

//    Silver challenge
CABasicAnimation *buttonSlide= [CABasicAnimation animationWithKeyPath:@"position"];
[buttonSlide setFromValue:[NSValue valueWithCGPoint:CGPointMake(320, 191+15)]];
[buttonSlide setToValue:[NSValue valueWithCGPoint:CGPointMake(160, 191+15)]];
[buttonSlide setDuration:.12];

[button.layer addAnimation:buttonSlide forKey:@"buttonSlide"];

[buttonSlide setDelegate:self];

CABasicAnimation *buttonFade= [CABasicAnimation animationWithKeyPath:@"opacity"];
[buttonFade setFromValue:[NSNumber numberWithFloat:.2]];
[buttonFade setToValue:[NSNumber numberWithFloat:1]];
[buttonFade setDuration:10];


}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
  NSLog(@"%@ finshed: %d",anim,flag);
  CAAnimation *buttonFade= [button.layer animationForKey:@"opacity"];
  [button.layer addAnimation:buttonFade forKey:@"buttonFade"];

}

The delegate method isn't logging to the console as its not even getting called..Please assist.

Upvotes: 2

Views: 1858

Answers (1)

Unheilig
Unheilig

Reputation: 16292

Put this:

[buttonSlide setDelegate:self];

Before:

[button.layer addAnimation:buttonSlide forKey:@"buttonSlide"];

Thus becomes:

[buttonSlide setDelegate:self];
[button.layer addAnimation:buttonSlide forKey:@"buttonSlide"];

Would work.

Hope this helps.

Upvotes: 4

Related Questions