2
我有一個UIView,其中包含CALayer(「layerPlot_」) 當y調用下面的方法它的工作原理,但它擴大了高度在兩個方向(上和下)我想指定,如果我想向下或向上擴展高度,並且圖層的另一邊保持在相同位置。CABasicAnimation擴展高度方向
的代碼如下:
/**
* 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位置。 – PaNaVTEC