Se llama inmediatamente a la finalización de CATransaction


Estoy tratando de ejecutar un bloque de finalización después de que mi CAAnimation haya terminado. Sin embargo, parece que el bloque de animación se llama antes de que mi animación se complete. Sin embargo, la animación sigue sucediendo correctamente.

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

El dropAndBounceAnimation es un CAKeyframeAnimation en la posición.y, con una duración fija.

Author: Javache, 2013-11-14

4 answers

No estoy seguro de si esta es realmente la solución correcta, pero al establecer el completion-block antes de agregar la animación para la capa, el completion-block se llama consistentemente en el momento correcto.

[CATransaction begin];
[CATransaction setCompletionBlock:completionBlock];
[self.view.layer addAnimation:self.dropAndBounceAnimation forKey:@"appearance"];
[CATransaction commit];
 88
Author: Javache,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-14 11:01:23

Debe establecer el bloque de animación antes de agregar la animación.

[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];

Esto debe activar el bloque de finalización después de la finalización de esa animación en la vista.

 11
Author: CoderSaru,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-10 07:15:42

Aquí está Swift 3.0.1, Xcode 8 versión:

CATransaction.begin()

CATransaction.setCompletionBlock({
  print("Transaction completed")
})

print("Transaction started")
view.layer.add(dropAndBounceAnimation, forKey: "appearance")

CATransaction.commit()
 2
Author: Vadim Bulavin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-28 14:47:07

Intenta iniciar la animación de forma asíncrona:

DispatchQueue.main.async {
    self.startAnimation()
}

Porque puede interferir con el dibujo de la vista si hace alguna configuración de vista antes de llamar a la animación.

 0
Author: mixel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-20 22:51:46