Core Animationなどをポリポリ研究

  1. [CATransaction flush]とは何か

    通常は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];
    }
    
    

    とかやってもダメ。

    1. do-nothing7ganoからリブログしました
    2. oppei7ganoからリブログしました
    3. 7ganoの投稿です

Theme = Manuscript Neue