Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATransaction completion being called immediately

I'm trying to execute a completion-block after my CAAnimation has finished. However, it seems that animation block is called before my animation completes. The animation still happens correctly though.

[CATransaction begin]; [self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"]; [CATransaction setCompletionBlock:completionBlock]; [CATransaction commit]; 

The dropAndBounceAnimation is a CAKeyFrameAnimation on position.y, with a fixed duration.

like image 279
Javache Avatar asked Nov 14 '13 11:11

Javache


2 Answers

I'm not sure if this really is the correct fix, but by setting the completion-block before adding the animation for the layer, the completion-block is consistently called at the correct time.

[CATransaction begin]; [CATransaction setCompletionBlock:completionBlock]; [self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"]; [CATransaction commit]; 
like image 94
Javache Avatar answered Oct 14 '22 04:10

Javache


You need to set the completion block before adding the animation.

[CATransaction begin]; [CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];  [CATransaction setCompletionBlock:^{ // ... whatever you want to do when the animation is complete }];  [self.googleMapsView animateToCameraPosition:[GMSCameraPosition                      cameraWithLatitude:LATITUDE                              longitude:LONGITUDE                                   zoom:ZOOM]];  [CATransaction commit]; 

This must trigger the completion block after the completion of that animation on the view.

like image 36
Saru Avatar answered Oct 14 '22 03:10

Saru