【问题标题】:CABasicAnimation expand height directionCABasicAnimation 展开高度方向
【发布时间】:2012-08-30 09:47:11
【问题描述】:

我有一个包含 CALayer ("layerPlot_") 的 UIView 当您调用以下方法时,它可以工作,但它会在两个方向(向上和向下)扩展高度我想指定是否要向下或向上扩展高度,并且图层的另一边保持在同一位置。

代码如下:

/**
 * 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 位置。

标签: iphone objective-c ios core-animation cabasicanimation


【解决方案1】:

您可以自己进行计算并为框架而不是边界设置动画,或者您可以将图层的锚点更改为底部,然后更新边界。

请注意,它将绘制相对于该点的所有内容,因此必须更新位置,否则它看起来会向上移动一半宽度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2019-02-06
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多