I am animating a layer like so to change the background color:
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
layer.backgroundColor = [UIColor yellowColor].CGColor;
[self.view.layer insertSublayer:layer atIndex:0];
[CATransaction begin];
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.y";
animation.byValue = @(-self.view.bounds.size.height);
animation.duration = 0.4;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
self.animating=YES;
[CATransaction setCompletionBlock:^{
NSLog(@"finished");
self.view.backgroundColor=[UIColor yellowColor];
[layer removeFromSuperlayer];
self.animating=NO;
}];
[layer addAnimation:animation forKey:@"slide"];
[CATransaction commit];
When I'm finished I set the actual background color of the UIView and then remove the layer. Do I need to call something like [self.view.layer removeAllAnimations];
in the completion block to remove the animation too or is it removed automatically? Just thinking about memory management.