CABasicAnimation - animationDidStop not called

被刻印的时光 ゝ 提交于 2019-12-21 21:32:24

问题


I am making a CABasicAnimation and the problem is that the animationDidStop delegate method does not get called. I am not sure why but hopefully someone knows.

Here is my animation:

CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath: @"transform.translation.x"];
theAnimation.duration = 54; 
//theAnimation.repeatCount = 6;
theAnimation.autoreverses = YES;
theAnimation.removedOnCompletion = YES; 

theAnimation.fromValue = [NSNumber numberWithFloat: (self.myImageView.frame.size.height / 5) + (self.view.frame.size.height - self.myImageView.center.x)];
theAnimation.toValue = [NSNumber numberWithFloat: 6.0 - (self.myImageView.frame.origin.y + self.myImageView.frame.size.height)];

//[self.myImageView.layer addAnimation:theAnimation forKey: @"animateLayer"];
[theAnimation setValue:@"Animation1" forKey:@"animateLayer"];
[[self.myImageView layer] addAnimation:theAnimation forKey:nil];

Also here is my animationDidStop method:

- (void)animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag {

    NSString* value = [theAnimation valueForKey:@"animateLayer"];
    if ([value isEqualToString:@"Animation1"])
    {
        [self themethod];
        return;
    }


    if ([value isEqualToString:@"Animation2"])
    {
        [self themethod];
        return;
    }
}

Does anyone knows why this is happening?


回答1:


You need to set delegate to call animationDidStop.

theAnimation.delegate = class (self)


来源:https://stackoverflow.com/questions/6446127/cabasicanimation-animationdidstop-not-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!