我正在尝试为图层设置动画,以使不透明度在大约 0.2 秒内从 0 变为 1,将不透明度保持在 1 秒,然后将不透明度恢复为 0。我正在尝试使用关键时间来做到这一点,但我无法正确处理。
CAKeyframeAnimation *opacityLabel = [CAKeyframeAnimation animationWithKeyPath: @"opacity"];
// 0.2 seconds fade in, 1 second hold, 0.2 seconds fade out
[opacityLabel setDuration: 1.4];
[opacityLabel setDelegate: self];
[opacityLabel setValue: @"countLabel" forKey: @"verify"];
[opacityLabel setValues: [NSArray arrayWithObjects: [NSNumber numberWithFloat: 1.0], [NSNumber numberWithFloat: 1.0], [NSNumber numberWithFloat: 0], nil]];
[opacityLabel setKeyTimes: [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0.2], [NSNumber numberWithFloat: 1.2], [NSNumber numberWithFloat: 1.4], nil]];
[[tomorrowCountLabel layer] addAnimation: opacityLabel forKey: @"opacityUp"];