【发布时间】:2015-02-21 10:44:25
【问题描述】:
我正在学习动画,但我遇到了一个问题。 我想显示一个高度从 1 开始到 100 的矩形。我希望这个矩形保持在视图的中间并扩大它的高度。
这是我目前制作的代码:
CAShapeLayer *rect = [CAShapeLayer layer];
CGRect frame = CGRectMake(0, 0,destView.frame.size.width, 1);
rect.frame = frame;
rect.path = [UIBezierPath bezierPathWithRect:frame].CGPath;
//DestView is the view that will receive this layer
rect.position = destView.center;
//For debug purpose
rect.fillColor = [UIColor blackColor].CGColor;
rect.strokeColor = [UIColor redColor].CGColor;
rect.anchorPoint = CGPointMake(0.5, 0.5);
CABasicAnimation *test = [CABasicAnimation animationWithKeyPath:@"bounds.size.height"];
[test setFromValue:[NSNumber numberWithFloat:1.0f]];
[test setToValue:[NSNumber numberWithFloat:100.0f]];
test.duration = 5.0f;
[test setFillMode:kCAFillModeForwards];
[rect addAnimation:test forKey:@"rectGrowing"];
[destView.layer addSublayer:rect];
我得到的结果是红线(1高度和红色笔划的矩形)从底部移动到中间......高度没有增加。
【问题讨论】:
-
好吧,它成功了,但我真的不明白为什么......
标签: ios objective-c calayer caanimation