animationDidStop:finished:不会调用委托方法
问题描述:
我想在前一个完成后立即开始一个新的动画例程。但是,如果前一个操作完成,则由于未调用委托方法,因此不会触发新操作。我委派了一个视图控制器来处理按钮的CALayer的动画。 'buttonSlide'是以前的动画,'buttonFade'是新的动画。 下面的代码片段: -animationDidStop:finished:不会调用委托方法
-(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"];
}
的委托方法不登录到控制台,它甚至没有得到called..Please协助。
答
把这个:
[buttonSlide setDelegate:self];
前:
[button.layer addAnimation:buttonSlide forKey:@"buttonSlide"];
因此变为:
[buttonSlide setDelegate:self];
[button.layer addAnimation:buttonSlide forKey:@"buttonSlide"];
会工作。
希望这会有所帮助。