我動畫化的CALayer的不透明度屬性與下面的代碼:CALayer的CABasicAnimation鏈接
創建的方法動畫:
+ (CABasicAnimation *)fadeIn:(float)begin duration:(float)duration remove:(BOOL)remove{
CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeAnimation.toValue = [NSNumber numberWithFloat:1.0];
fadeAnimation.additive = NO;
fadeAnimation.removedOnCompletion = remove;
fadeAnimation.beginTime = begin;
fadeAnimation.duration = duration;
fadeAnimation.fillMode = kCAFillModeBoth;
return fadeAnimation;
}
添加動畫層:
[overlayLayer addAnimation:[VideoComposerHelpers fadeIn:1.0 duration:0.5 remove:NO] forKey:nil];
這是工作完美。但是,現在我想在第一個動畫完成之後,向同一圖層添加另一個動畫。
[overlayLayer addAnimation:[VideoComposerHelpers fadeOut:1.5 duration:0.5 remove:NO] forKey:nil]; // fadeOut is a method similar to fadeIn
應該發生的事情是,圖層淡入持續時間爲0.5,然後淡出持續時間爲0.5。 雖然這似乎不起作用。是否因爲第二個動畫的起始點與第一個動畫的起點相同?
很高興我能幫助,我希望那個投下了贊成票的人也許在我的回答中出錯了(無論如何,我只是複製粘貼一段我的運行代碼,然後根據需要進行調整),所以基本上它應該是一個好的答案:)) – danypata