I have a UIView that contains a CALayer (“layerPlot_”)
When y call the following method it works but it expands the height in both directions (up and down) I want to specify if I want to expand the height down or up and the other edge of the layer maintains at the same position.
The code is the following:
/**
* Resizes the layer to a new height.
*
* @param newHeight the new height of the layer
*/
-(void)resizeLayerTo:(CGFloat)newHeight {
// Create animation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds.size.height"];
[animation setFromValue:[NSNumber numberWithFloat:0.0f]];
[animation setToValue:[NSNumber numberWithFloat:newHeight]];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setFillMode:kCAFillModeForwards];
[animation setDuration:1.2f];
// Update the layer's bounds so the layer doesn't snap back when the animation completes.
CGRect newSize = [layerPlot_ bounds];
newSize.size.height = newHeight;
layerPlot_.bounds = newSize;
// Add the animation, overriding the implicit animation.
[layerPlot_ addAnimation:animation forKey:@"bounds"];
}
Thanks.
You could either do the calculations yourself and animate the frame instead of the bounds or you could change the anchorPoint of the layer to the bottom and then update the bounds.
Note that it will draw all it’s content relative to that point so the position will have to be updated or else it will look shifted half the width upwards.