通常はRunLoopの終わりで勝手に呼ばれる。
なので呼ぶ必要は無いんだけど、何かの事情でRunLoopがその後終了しないとき
呼んであげると、アニメーションが始まる。
たとえば、こんなコードで試せる。
[CATransaction flush]を呼ばないとアニメーションしない。
- (void)action
{
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 2.0;
[_layer addAnimation:animation forKey:nil];
//Call flush self!
[CATransaction flush];
while (1) {
//block current Run Loop
}
}
あくまで、Current Run Loopなので外から とかやってもダメ。[self performSelector:@selector(flush) withObject:nil afterDelay:1.0];
- (void)flush
{
[CATransaction flush];
}