Iphone 卡巴斯基化展开高度方向
我有一个UIView,其中包含一个CALayer(“layerPlot”) 当y调用以下方法时,它会工作,但会在两个方向(向上和向下)扩展高度。我想指定是向下扩展高度还是向上扩展高度,并且层的另一条边保持在相同的位置 代码如下:Iphone 卡巴斯基化展开高度方向,iphone,objective-c,ios,core-animation,cabasicanimation,Iphone,Objective C,Ios,Core Animation,Cabasicanimation,我有一个UIView,其中包含一个CALayer(“layerPlot”) 当y调用以下方法时,它会工作,但会在两个方向(向上和向下)扩展高度。我想指定是向下扩展高度还是向上扩展高度,并且层的另一条边保持在相同的位置 代码如下: /** * Resizes the layer to a new height. * * @param newHeight the new height of the layer */ -(void)resizeLayerTo:(CGFloat)newHeigh
/**
* 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"];
}
谢谢。您可以自己计算并设置帧动画,而不是边界,或者将层的固定点更改为底部,然后更新边界
请注意,它将绘制相对于该点的所有内容,因此必须更新位置,否则它将向上移动一半宽度 对不起,我只是忘了说,在调用此方法之前,我正在重新定位此层的Y位置。