여러개의 루프를 반복하여 각각의 애니메이션을 수행하려고합니다. 그러나 모든 애니메이션이 끝났음을 알고 싶습니다. 애니메이션 반복이 끝나면 함수를 호출하는 가장 좋은 방법은 무엇입니까? 또는 모든 것이 완료 될 때까지 기다릴 수있는 방법이 있습니까?UIView 애니메이션 반복을 마칠 때까지 기다리는 가장 좋은 방법은 무엇입니까?
setAnimationDidStopSelector
을 사용해 보았지만 시작되지 않습니다. 이 경우 게임 보드에서 "칩"을 지우고 사라지게하여 제거합니다 (NumberedChipView는 UIView의 하위 클래스 임). 칩이 보드에서 빠져 나올 때까지 플레이를 계속할 수 없습니다.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop)];
// clear chips
for (HexagonalTile *aTile in tilesToClear) {
NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
chipView.alpha = 0.0;
}
completion:^(BOOL finished){
if (finished) {
[chipView removeFromSuperview];
[self.chipViews removeObject:chipView];
}
}];
}
[UIView commitAnimations];
는 또한 아무 소용 CATransaction
을 시도 :
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[self animationFinished];
}];
// clear chips
for (HexagonalTile *aTile in tilesToClear) {
NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
chipView.alpha = 0.0;
}
completion:^(BOOL finished){
if (finished) {
[chipView removeFromSuperview];
[self.chipViews removeObject:chipView];
//NSLog(@"clearing finished");
}
}];
}
[CATransaction commit];
업데이트 :
지금 발사 셀렉터를 얻을 수 있습니다, 그러나 그것은 애니메이션의 루프 기다리지 않습니다끝내기 위해.
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
여기서 단점은 완성 블록이 애니메이션이 별도의 스레드에서 발생하여 동시에 발생한다는 것입니다. 따라서 지연 변수로 원 자성을 보장해야합니다. 나는 이것과 같은 것을 시도했고 그것은 단지 매달릴 것이다. –
이 애니메이션 동시성에 대한 Apple 문서 (https://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/AnimatingViews/AnimatingViews)를 참조하십시오.html # // apple_ref/doc/uid/TP40009503-CH6-SW3 –
물론 UIView beginAnimation/commitAnimation 메소드는 이전 스타일이며, Apple docs는 블록 기반 메소드가 선호된다고 말합니다. 그러나이 경우 블록 기반 방법을 작동시키는 방법을 실제로 파악할 수 없었습니다. –