I’m getting this error:

With this code:
-(void)lowerGUI {
[mainGUI.layer addAnimation:guiLower forKey:@"transform.translation.y"];
}
I have a UIView which I’m animating up and down to move it out of the way if needed. I’ve set up my animation in viewDidLoad:
guiLower = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
guiLower.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
guiLower.duration = 1;
guiLower.fromValue = [NSNumber numberWithFloat:320];
guiLower.toValue = [NSNumber numberWithFloat:481];
The code builds and runs fine, but when I click the button to run the animation, the error appears.
Any ideas?
Thank you.
Chances are that you should hold a reference to your animation:
in an ivar or property of your class and make sure that the object you assign to it is properly retained. Indeed,
EXC_BAD_ACCESSis commonly caused by accessing an already deallocated instance of an object.Example:
in .h file:
in .m file: