我知道您必须使用此方法来获取动画完成时的委托方法:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
问题是,我如何区分像2或更多这样的多个CAAnimations?
我用谷歌搜索了一下,但我没有找到任何有用的东西。
请与我分享你是如何做到这一点的!
谢谢!
发布于 2011-10-13 16:45:12
您可以像这样设置CAAnimation实例的键/值对象:
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[theAnimation setValue:@"animation1" forKey:@"id"];
theAnimation.delegate = self;
CABasicAnimation *theAnimation2 = [CABasicAnimation animationWithKeyPath:@"opacity"];
[theAnimation2 setValue:@"animation2" forKey:@"id"];
theAnimation2.delegate = self;
检查委托方法中调用的是哪一个:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if([[anim valueForKey:@"id"] isEqual:@"animation1"]) {
NSLog(@"animation1");
}
if([[anim valueForKey:@"id"] isEqual:@"animation2"]) {
NSLog(@"animation2");
}
}
发布于 2016-06-01 20:47:15
CAAnimation
对象应该时不时地被重用,这就是为什么我不喜欢给它一个特定的键(因为它不是唯一的)。它的独特之处在于它与CALayer和addAnimation:forKey:
的关联。出于这个原因,我在animationDidStop
中使用了以下代码
if animation == layer.animationForKey(AnimationKeys.scaleUp) {
// scaleUp animation has completed
}
https://stackoverflow.com/questions/7748722
复制相似问题