我想要通過一組CATextLayers來一個接一個地動畫。層創建並添加在一個循環中。我需要動畫才能像翻書一樣工作。到目前爲止,作爲概念證明,我已經使用了CABasicAnimations,但爲了按順序動畫多個圖層,我認爲我需要其他核心動畫選項之一,但我不確定哪一個。這裏的循環添加子層:如何在覈心動畫子圖層數組中循環並按順序應用動畫
- (void) initLayers: (NSString *)endChar
{
CALayer *rootLayer = self.layer;
int counter =0;
for (NSString *element in alphabet) {
NSLog(@"element: %@",element);
NSString *topLayerName = [NSString stringWithFormat:@"TOP_%d_%@",counter,element];
NSString *bottomLayerName = [NSString stringWithFormat:@"BOT_%d_%@",counter,element];
//get index of endchar - indexOfObject
if (element != endChar) { //change to if key value is less than or equal to endchar index value
CATextLayer *topLayer = [CATextLayer layer];
topLayer.name = topLayerName;
[topLayer setAnchorPoint:CGPointMake(0.5f,1.0f)]; // set the anchorpoint for the transform. This affects layer position too
topLayer.bounds = CGRectMake(0.0f, 0.0f, CHARACTER_WIDTH, CHARACTER_HEIGHT/2);
topLayer.string = element;
topLayer.font = solariFont.fontName;
topLayer.fontSize = FONT_SIZE;
topLayer.backgroundColor = [UIColor blackColor].CGColor;
topLayer.position = CGPointMake(30,30);
topLayer.wrapped = NO;
[rootLayer addSublayer:topLayer];
CATextLayer *bottomLayer = [CATextLayer layer];
bottomLayer.name =bottomLayerName;
[bottomLayer setAnchorPoint:CGPointMake(0.5f,0.0f)]; // set the anchorpoint for the transform. This affects layer position too
bottomLayer.bounds = CGRectMake(0.0f,CHARACTER_HEIGHT/4, CHARACTER_WIDTH, CHARACTER_HEIGHT/2);
bottomLayer.string = element;
bottomLayer.font = solariFont.fontName;
bottomLayer.fontSize = FONT_SIZE;
bottomLayer.backgroundColor = [UIColor blackColor].CGColor;
bottomLayer.position = CGPointMake(topLayer.position.x,topLayer.position.y+2);
bottomLayer.wrapped = NO;
[rootLayer addSublayer:bottomLayer];
counter++;
}
}
[self animChars:rootLayer.sublayers];
}
的問題是我怎麼能動畫後,其他各層一個沒有動畫的每一層都在同一時間發生?我希望能夠遍歷子層數組,並依次爲每個CATextLayer設置動畫。我需要CATransactions,MediaTiming嗎?我已經通過核心動畫指南,但沒有比這更明智的了。