【问题标题】:CABasicAnimation - animationDidStop not calledCABasicAnimation - 未调用 animationDidStop
【发布时间】:2011-06-22 20:26:17
【问题描述】:

我正在制作 CABasicAnimation,但问题是 animationDidStop 委托方法没有被调用。我不知道为什么,但希望有人知道。

这是我的动画:

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

这也是我的 animationDidStop 方法:

- (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;
    }
}

有人知道为什么会这样吗?

【问题讨论】:

    标签: caanimation


    【解决方案1】:

    您需要设置委托来调用animationDidStop

    theAnimation.delegate = class (self)
    

    【讨论】:

    • 请注意CAAnimationdelegate 很强大,因此您可能需要将其设置为nil 以避免保留循环!
    • 谢谢,但在 2011 年“强大”可能还没有实现...... :)
    • 我知道,这是为了其他人会遇到这个,因为我很难学会它,并且在互联网上的任何地方都没有看到它:(
    猜你喜欢
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多