我使用3层在UIView对象中构建了自定义进度条:
对图层2进行动画处理,以便在一段时间内(通常约为2分钟)均匀地将边界宽度从0扩展到320。它工作正常,但不像我预期的那样顺利 有关如何提高性能或使用其他/其他动画技术使其看起来更均匀移动的想法吗?
创建第2层的代码是:
- (void)drawForegroundLayer {
CGColorRef startColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0].CGColor;
CGColorRef endColor = [UIColor colorWithRed:239.0/255.0 green:125.0/255.0 blue:0.0 alpha:1.0].CGColor;
CAGradientLayer *foregroundLayer = [CAGradientLayer layer];
foregroundLayer.frame = CGRectMake(0, 2, 0, 13);
foregroundLayer.anchorPoint = CGPointMake(0.0,0.5);
foregroundLayer.colors = [NSArray arrayWithObjects:(id)startColor, (id)endColor, nil];
foregroundLayer.borderWidth = 0;
foregroundLayer.edgeAntialiasingMask = kCALayerRightEdge;
[self.layer addSublayer:foregroundLayer];
}
动画第2层的代码是:
- (void)start {
CALayer *bar = [[self.layer sublayers] objectAtIndex:1];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
animation.toValue = [NSNumber numberWithFloat:320.0];
animation.duration = MAXIMUM_TIME_PER_SESSION;
[bar addAnimation:animation forKey:nil];
}