J'ai une image que je place dans un calayer, puis j'ajoute ce calque comme sous-calque de la vue principale. Quand j'essaie de l'animer autour de son axe Z, tout ce que je vois est une image statique.Pourquoi mon calque ne s'anime-t-il pas autour de l'axe Z?
Pourquoi mon calque ne s'anime-t-il pas? Le code pertinent est le suivant:
- (void)viewDidLoad {
UIImage *myImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"png"]];
earthLayer = [CALayer layer];
[earthLayer setContents:(id)[myImage CGImage]];
[earthLayer setBounds:CGRectMake(240,360, 40, 200)];
[earthLayer setPosition:CGPointMake(280, 280)];
[earthLayer setName:@"earth"];
[earthLayer addAnimation:[self animationForSpinning] forKey:@"Rahul"];//here animatin is being added to the layer..
[[self.view layer] addSublayer:earthLayer];
//[self spinLayer:earthLayer];
}
//the animation method which returns a CAAnimation.
- (CAAnimation*)animationForSpinning {
// Create a transform to rotate in the z-axis
float radians = DegreeToRadian(360);
CATransform3D transform;
transform = CATransform3DMakeRotation(radians, 0, 1.0,0, 1.0);
// Create a basic animation to animate the layer's transform
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
// Now assign the transform as the animation's value. While
// animating, CABasicAnimation will vary the transform
// attribute of its target, which for this transform will spin
// the target like a wheel on its z-axis.
animation.toValue = [NSValue valueWithCATransform3D:transform];
animation.duration = 2; // two seconds
animation.cumulative = YES;
animation.repeatCount = 10000;// "forever"
return animation;
}
Thanx Brad. J'ai résolu le problème. – Rahul
Si Brad a résolu votre problème, alors il devrait marquer sa réponse comme la réponse acceptée. ;-) –