Giratoria NSView que mantiene una NSImageView
-
20-09-2019 - |
Pregunta
Estoy creando un NSView, que en su método drawRect crea y añade un NSImageView como subvista.
Me gustaría hacer girar esta NSImageView (Circleview), o [libre]. Así, en otro método, yo estoy tratando de hacer lo siguiente:
-(void)startAnimation {
CABasicAnimation* spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
spinAnimation.toValue = [NSNumber numberWithFloat:5*2*M_PI];
spinAnimation.duration = 2;
[circleView.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
}
Sin embargo, este código no hace nada cuando se llama al método. ¿Estoy haciendo algo mal? Probé self.layer y circleView.layer pero ninguno parece funcionar ...
Solución
Tu eres simplemente definir la animación, usted no está realmente llamar el bloque de animación que realiza la animación.
Es necesario llamar a un bloque definido entre:
+ beginAnimations:context:
+ commitAnimations
Para ejecutar realmente la animación.
Edit01: Mi mal. No presté atención a las etiquetas y añadió que la respuesta de la API de iPhone.
Otros consejos
La respuesta a esta cuestión es que la NSView / NSImageView no tenía una capa de soporte que ver con la animación.
Se establece esto con:
[NSView setWantsLayer:YES];