How to wait for an animator to finish?

前端 未结 3 680
旧时难觅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!");
    }];
    

提交回复
热议问题