2010-08-11 5 views
1

애니메이션 ([UIView commitAnimations]로 호출)이 별도의 스레드에서 실행된다는 사실에 대한 문서가 명확합니다. 무엇이 명확하지 않은가 (나에게있어, 어쨌든) animationDidStopSelector가 메인 (UI) 스레드에서 실행되는지 또는 애니메이션과 동일한 스레드에서 실행되는지 여부이다.iPhone : 애니메이션 정지 선택기가 주 스레드에서 실행됩니까?

주어진 다음의 코드는 다음 animationDone 호출이 다른 스레드에서 발생, 그래서 만약

- (void) doSomethingCool { 
// Fade out someView 
[UIView beginAnimations:@"myAnimation" context:nil]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)]; 
someView.alpha = 0.0; 
[UIView commitAnimations]; 
} 

- (void) animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
if([animationID isEqual:@"myAnimation"]) { 
    [someView removeFromSuperview]; 
} 
} 

나는 다음 주 스레드가 아닌 다른 스레드에서 UI 요소에 액세스하는 "일반적으로 나쁜"이라고 들었습니다 위의 코드는 나쁜 일을 할 것입니다, 네?

나쁜 일을하지 않는 것 같습니다. 그러나 나는이 애니메이션 이후에 일어나는 겉으로보기에는 무작위적인 충돌을 쫓아왔다. 그리고 스레딩 문제가 있는지 궁금하다.

답변

1

잘 배치 된 몇 개의 NSLog 호출을 통해 입증 된 것처럼, 은 주 스레드에서 실행되는입니다.

executing beginAnimations on thread <NSThread: 0x6b10860>{name = (null), num = 1} 
executing animationDone on thread <NSThread: 0x6b10860>{name = (null), num = 1} 

을 ... 내 충돌 정말 어디 있는지 궁금하게하는 : 출력

- (void) doSomethingCool { 
    // Fade out someView 
    NSLog(@"executing beginAnimations on thread %@", [NSThread currentThread]); 
    [UIView beginAnimations:@"myAnimation" context:nil]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)]; 
    someView.alpha = 0.0; 
    [UIView commitAnimations]; 
} 

- (void) animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    NSLog(@"executing animationDone on thread %@", [NSThread currentThread]); 
    if([animationID isEqual:@"myAnimation"]) { 
     [someView removeFromSuperview]; 
    } 
} 

.... : P

+0

그것은 당신과 대화입니다! :)하지만 말하기를 원한다. 나는 정지 점에 중단 점을 넣고 디버거의 스레드를 보았을 것이다. – nielsbot

관련 문제