www whatwg spec language 3wc iphone core-animation

iphone - whatwg - Animation End Callback para CALayer?



w3c html standards (6)

Me pregunto dónde están las devoluciones de llamada (o si hay algo) para las animaciones en un CALayer. Específicamente, para animaciones implícitas como alterar el marco, la posición, etc. En una UIView, podrías hacer algo como esto:

[UIView beginAnimations:@"SlideOut" context:nil]; [UIView setAnimationDuration:.3]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animateOut:finished:context:)]; CGRect frame = self.frame; frame.origin.y = 480; self.frame = frame; [UIView commitAnimations];

Específicamente, el setAnimationDidStopSelector es lo que quiero para una animación en un CALayer. ¿Hay algo por el estilo?

TIA.


Puede configurar el nombre de una animación determinada al configurar el objeto CAAnimation. En animationDiStop: finalizado, simplemente compare el nombre del objeto Animation proporcionado para realizar su funcionalidad específica basada en la animación.


Respondí mi propia pregunta. Tienes que agregar una animación usando CABasicAnimation manera:

CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"frame"]; anim.fromValue = [NSValue valueWithCGRect:layer.frame]; anim.toValue = [NSValue valueWithCGRect:frame]; anim.delegate = self; [layer addAnimation:anim forKey:@"frame"];

E implemente el método de delegado animationDidStop:finished: y debería estar listo para continuar. ¡Gracias a Dios que esta funcionalidad existe! :RE


Solo una nota para quienes encuentran esta página en Google: realmente puedes hacer el trabajo estableciendo la propiedad "delegar" de tu objeto de animación en el objeto que recibirá la notificación e implementando el método "animationDidStop" en el .m de ese objeto. archivo. Lo intenté y funciona. No sé por qué Joe Blow dijo que esa no era la forma correcta.


Perdí 4 horas con esta basura, solo para desvanecerme. Tenga en cuenta el comentario en el código.

[CATransaction begin]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation.duration = 0.3; animation.fromValue = [NSNumber numberWithFloat:0.0f]; animation.toValue = [NSNumber numberWithFloat:1.0f]; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeBoth; /// [box addAnimation:animation forKey:@"j"]; Animation will not work if added here. Need to add this only after the completion block. [CATransaction setCompletionBlock:^{ CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"opacity"]; animation2.duration = 0.3; animation2.beginTime = CACurrentMediaTime()+1; animation2.fromValue = [NSNumber numberWithFloat:1.0f]; animation2.toValue = [NSNumber numberWithFloat:0.0f]; animation2.removedOnCompletion = NO; animation2.fillMode = kCAFillModeBoth; [box addAnimation:animation2 forKey:@"k"]; }]; [box addAnimation:animation forKey:@"j"]; [CATransaction commit];


Aquí hay una respuesta en Swift 3.0 basada en la solución de bennythemink:

// Begin the transaction CATransaction.begin() let animation = CABasicAnimation(keyPath: "strokeEnd") animation.duration = duration //duration is the number of seconds animation.fromValue = 0 animation.toValue = 1 animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) circleLayer.strokeEnd = 1.0 // Callback function CATransaction.setCompletionBlock { print("end animation") } // Do the actual animation and commit the transaction circleLayer.add(animation, forKey: "animateCircle") CATransaction.commit()


Podría usar una CATransaction, tiene un controlador de bloques de finalización.

[CATransaction begin]; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; [pathAnimation setDuration:1]; [pathAnimation setFromValue:[NSNumber numberWithFloat:0.0f]]; [pathAnimation setToValue:[NSNumber numberWithFloat:1.0f]]; [CATransaction setCompletionBlock:^{_lastPoint = _currentPoint; _currentPoint = CGPointMake(_lastPoint.x + _wormStepHorizontalValue, _wormStepVerticalValue);}]; [_pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"]; [CATransaction commit];