2011-11-09 2 views
0

내가 CALayer의 서브 클래스 MyLayer라고 있습니다[CALayer animationForKey :]의 신뢰성은 어느 정도입니까?

@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-234 초가 걸리기 시작하여 nil -s가 시작됩니다. 내가 animation.delegate = self을 애니메이션과animationDidStop:finished:을 구현하는 대리자를 설정하면

이 이상한 행동 사라집니다.

누구에게도이 경험이 있습니까?

+0

메인 스레드에서 animationForKey로 확인 하시겠습니까? –

+0

예, 메인 GUI 스레드의 모든 것 ... – debleek63

+0

위와 같은 동작을 보았습니다. 위임자를 추가하면 'animationDidStop : finished :'메서드가 예상되는 동작을 시작합니다. 매우 이상합니다. 코어 애니메이션 버그? 다른 솔루션? –

답변

0

@dynamic을 선언하면 CALayer가 접근 자 메서드를 구현합니다 (Properties on CALayer subclass aren't getting observed by CATransactionCALayer and CAAnimation's dynamic resolution of unimplemented property accessors 참조). 따라서 "바쁜"버전이 불려지는 혼란을 겪고있는 것일 수 있습니다. 왜 당신은 "@dynamic"을 처음부터 선언 했습니까?

animationForKey로 인해 펑키 한 일이 발생할 수도 있지만, 먼저 "@dynamic"을 제거하려고합니다.

관련 문제