I’m trying to make a compass.
Basically I use an image of a compass needle as the directions-thing for the compass. It’s animating fine around the center of the compass UNTIL I switch view, or add another view (ex. UIActionView or switch to another view controller):
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
float oldRadian = (-manager.heading.trueHeading *M_PI /180.0f);
float newRadian = (-newHeading.trueHeading *M_PI /180.0f);
CABasicAnimation *animation;
animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:oldRadian];
animation.toValue = [NSNumber numberWithFloat:newRadian];
animation.duration = 0.5f;
[compassArrow.layer addAnimation:animation forKey:@"animateMyRotation"];
compassArrow.transform = CGAffineTransformMakeRotation(newRadian);
}
After this I’m switching to another view controller that is the compassArrow imageview that was animating & started floating around.
Any ideas why this happens??
I solved it using the removeFromSuperlayer-method before I change view. Problem was that I created multiple animations for the same key (@”animateMyRotation”).