【发布时间】: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