How to wait for an animator to finish?

前端 未结 3 673
旧时难觅i
旧时难觅i 2021-01-06 02:35

This is probably a simple question but I can\'t seem to figure out how to do it. Basically all I want to do is fade a window before closing it:

[[window anim         


        
相关标签:
3条回答
  • 2021-01-06 03:01

    This is an old (but still popular) question with obsolete answer.

    The right way to wait for animator finished is using special NSAnimationContext's class method with completionHanler like this:

    [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
        // Start some animations here.
        [[window animator] setAlphaValue:0.0];
    } completionHandler:^{
        // This block will be invoked when all of the animations started above have completed or been cancelled.
        NSLog(@"All done!");
    }];
    
    0 讨论(0)
  • 2021-01-06 03:06

    Implicit animations triggered through the animator proxy run on wall time. Get the duration from the current NSAnimationContext and perform delay your cleanup/post-animation operations using that interval.

    0 讨论(0)
  • 2021-01-06 03:10
    [[window animator] setAlphaValue:0.0];
    [window performSelector:@selector(performClose:) withObject:self afterDelay:[[NSAnimationContext currentContext] duration]];
    
    0 讨论(0)
提交回复
热议问题