-(void) movePinsToDestinations:(NSArray *)destination withCompletion: (void (^)())block
{
...
[UIView animateWithDuration:animationTime animations:^{
//[self.ReloadBut setTitle:@"Animating " forState:UIControlStateNormal];
for (BGAddressAnnotation * anExistingAnnotation in existingAnnotations) {
if (anExistingAnnotation.destination) {
anExistingAnnotation.coordinate = anExistingAnnotation.destination.coordinate;
}
else
{
anExistingAnnotation.myView.alpha = 0;
}
}
} completion:^(BOOL finished){
NSAssert(finished, @"Not Finished?");
for (BGAddressAnnotation * existingAnnotation in existingAnnotations) {
if ([existingAnnotation.destination.myBiz isEqual: existingAnnotation.myBiz]) {
existingAnnotation.arrayOfBusinesses = existingAnnotation.destination.arrayOfBusinesses;
existingAnnotation.myView.alpha=1;
}
else
{
[self.theMapView removeAnnotation:existingAnnotation];
}
}
// PO([[self class] PrintAllAnnotations: [self annotationExceptUser]]);
// PO([[self class] PrintAllAnnotations: destination]);
PO(@"Reach Completion Block");
if (block)
{
block();
}
else
{
//[self.ReloadBut setTitle:@"Animating Finish" forState:UIControlStateNormal];
}
}];
}
结果:
2012-11-04 20:00:05.800 @"Start Animating": Start Animating
2012-11-04 20:00:05.805 @"Reach Completion Block": Reach Completion Block
我将动画设置为运行 10 秒,但在 5 毫秒内调用完成块。有什么可能做到这一点?
在某些背景下,该函数被调用了两次,并且完成块应该调用另一个动画。第二个动画确实在 10 秒内完成。指定完成块会立即调用它还是什么?
所以我正在有效地做
[self movePinsToDestinations:self.myCache.annotationsInterMediateState withCompletion:^{
[self movePinsToDestinations:self.myCache.annotationsWeShouldbeDisplaying withCompletion:^{
}];
}];
更新:
出于好奇,我多次嵌套动画。
[self movePinsToDestinations:self.myCache.annotationsInterMediateState withCompletion:^{
[self movePinsToDestinations:self.myCache.annotationsWeShouldbeDisplaying withCompletion:^{
[self movePinsToDestinations:emptyAnnotations withCompletion:^{
[self movePinsToDestinations:startOff withCompletion:^{
[self movePinsToDestinations:self.myCache.annotationsInterMediateState withCompletion:^{
[self movePinsToDestinations:self.myCache.annotationsWeShouldbeDisplaying withCompletion:^{
}];
}];
}];
}];
}];
}];
结果如下:
21:51.9 Start Animating: Start Animating
21:51.9 (animationTime): 10
21:51.9 Reach Completion Block: Reach Completion Block
21:51.9 Start Animating: Start Animating
21:51.9 (animationTime): 10
21:51.9 Reach Completion Block: Reach Completion Block
21:51.9 Start Animating: Start Animating
21:51.9 (animationTime): 10
22:01.9 Reach Completion Block: Reach Completion Block
22:01.9 Start Animating: Start Animating
22:01.9 (animationTime): 10
22:01.9 Reach Completion Block: Reach Completion Block
22:01.9 Start Animating: Start Animating
22:01.9 (animationTime): 10
22:01.9 Reach Completion Block: Reach Completion Block
22:01.9 Start Animating: Start Animating
22:01.9 (animationTime): 10
22:01.9 Reach Completion Block: Reach Completion Block
因此,其中一个动画已正确完成,并且在开始动画后 10 秒调用了该块。
可能会立即调用该块,因为在 viewDidAddAnnotation 中正在调用另一个动画,但是不太可能是这种情况,因为可以同时调用许多不同的动画。
大多数动画仍然只运行几毫秒。有些跑了 3 秒。不应运行其他动画。