Я изучаю канимации, и я сталкиваюсь с проблемой. Я хочу отобразить прямоугольник, высота которого начинается с 1 и идет до 100. Я хочу, чтобы этот прямоугольник оставался посередине представления и просто расширял его высоту.Изменение высоты слоя с использованием caanimation
это код, я сделал до сих пор:
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 и красный инсульт), движущегося снизу до середины ... Высота не увеличивается.
http://stackoverflow.com/questions/11463438/cabasicanimation-with-calayer-path-doesnt-animate – Wain
Хорошо, что это трюк, но я действительно не понимаю, почему ... –