I'm facing a strange issue on CAKeyFrameAnimation.
Here's the code:
//Inside the selector method of the button
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[anim setDelegate:self];
anim.path = racetrack.path;
anim.rotationMode = kCAAnimationRotateAuto;
anim.repeatCount = 0;
anim.duration = 10.0;
[carBtn.layer addAnimation:anim forKey:@"race"];
The animation works fine. The problem occurs when the carBtn (a button with a car background image) is pressed. The button's image rotate by 180° for no reason (at least no reason for me). I've to rotate the button myself with this line of code after the creation of the animation
carBtn.transform = CGAffineTransformMakeRotation(M_PI);
...but for a second or two (before the animation starts) the car is faced opposite to its initial position. The button is created in this way:
UIImage* car = [UIImage imageNamed:@"car_image"];
carBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[carBtn setFrame:CGRectMake(startPoint.x-45, startPoint.y-33, macchina.size.width, macchina.size.height)];
[carBtn setBackgroundImage:car forState:UIControlStateNormal];
[carBtn setBackgroundImage:car forState:UIControlStateHighlighted];
[carBtn addTarget:self action:@selector(carPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:carBtn];
How could this be possible? Thanks