我有一个包含 CALayer ("layerPlot_") 的 UIView 当 y 调用以下方法时它起作用但它会在两个方向(向上和向下)扩展高度我想指定是否要向下或向上扩展高度并且图层的另一边缘保持在同一位置。
代码如下:
/**
* 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"];
}
谢谢。
最佳答案
您可以自己进行计算并为框架而不是边界设置动画,或者您可以将图层的 anchor 更改为底部,然后更新边界。
请注意,它会绘制相对于该点的所有内容,因此必须更新位置,否则它看起来会向上移动一半的宽度。
关于iphone - CABasicAnimation 展开高度方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12194134/