3
我正在嘗試動態化圖層,以便在大約0.2秒內不透明度從0變爲1,將不透明度保持爲1秒,然後將不透明度恢復爲0.我嘗試使用關鍵時間做到這一點,但我無法做到。如何在CAKeyFrameAnimation中使用關鍵時間來動畫化圖層的不透明度?
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"];
@aLevelOfInderection謝謝! – bbraunj 2013-04-14 18:52:37
如果這對你有用,不要忘記接受答案。 – aLevelOfIndirection 2013-04-14 18:56:44