iphone - CABasicAnimation 展开高度方向

标签 iphone objective-c ios core-animation cabasicanimation

我有一个包含 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/

相关文章:

iphone - 更改 UIScrollView 上的页面

ios - 更改 UISegmentedControl 的边框颜色

ios - NSString 中的数值显示在错误的语言环境中

ios - 尝试在 ChartDataEntry 中输入日期/字符串

ios - UITabBarButton 无需切换到另一个 View

iphone - applicationWillTerminate 何时调用,何时不调用

iphone - 通过相机进行形状识别的 iPhone 库

ios - 如何创建小型 tableView Controller ?

ios - 通过 POST 方法发送带有其他参数的图像

iphone - startDownloadingUbiquitousItemAtURL 本地文件路径?