gpt4 book ai didi

ios - animationDidStop : finished: delegate method not getting called

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:03:59 25 4
gpt4 key购买 nike

我想在前一个动画例程完成后立即开始一个新的动画例程。然而,当前一个确实完成时,新的不会被触发,因为没有调用委托(delegate)方法。我已经委派了一个 View Controller 来处理按钮的 CALayer 的动画。 “buttonSlide”是以前的动画,而“buttonFade”是新动画。 这是代码片段:-

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

}

委托(delegate)方法没有记录到控制台,因为它甚至没有被调用。请协助。

最佳答案

把这个:

[buttonSlide setDelegate:self];

之前:

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

这样就变成了:

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

会起作用。

希望这对您有所帮助。

关于ios - animationDidStop : finished: delegate method not getting called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25627118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com