我有一个CALayer
名为的子类MyLayer
:
@interface MyLayer : CALayer
@property (nonatomic,readonly) BOOL busy;
-(void)performTask1;
-(void)performTask2;
-(void)performTask3;
@end
在performTask*
函数中我说:
-(void)performTask*
{
CAKeyframeAnimation *animation = [...];
...
animation.removedOnCompletion = YES; // "YES" is default anyway
...
[self addAnimation:animation
forKey:TASK*_KEY];
}
该busy
属性用于调用者,并像这样实现:
@dynamic busy;
-(BOOL)busy
{
// i.e. for some specific ids
return ([self animationForKey:TASK1_KEY] != nil ||
[self animationForKey:TASK3_KEY] != nil);
}
我看到的是这种方法不可靠......我可以在屏幕上看到动画已经完成(没有任何东西在移动等),而animationForKey:
没有返回nil
。行为是半随机的......大多数时候它都按预期进行。但有时我需要 1-2 秒才能开始获取nil
-s。
如果我将委托设置为动画并实现,这种奇怪的行为就会消失。animation.delegate = self
animationDidStop:finished:
有人也经历过吗?