animationDidStop:finished:委托方法未被调用

时间:2014-09-02 15:31:20

标签: ios objective-c cocoa-touch caanimation

我想在上一个动画例程完成后立即启动它。但是,当前一个完成时,由于未调用委托方法,因此不会触发新的触发器。我已委派了一个视图控制器来处理按钮的CALayer的动画。 ' buttonSlide'是以前的动画,而按钮淡出'是新的。   这是代码段: -

-(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"];

}

委托方法没有登录到控制台,因为它甚至没有被调用。请帮助。

1 个答案:

答案 0 :(得分:3)

把这个:

[buttonSlide setDelegate:self];

在:

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

因此成为:

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

会工作。

希望这有帮助。