为什么NSAnimationContext completeHandler不起作用(有时)?

Hof*_*ofi 3 objective-c nsanimationcontext completionhandler


    // wc here is an NSWindowController

    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:0.5f];

    if (duplication) {
        NSPoint origin = initialSize.origin;
        origin.y += initialSize.size.height;
        origin = [wc.window cascadeTopLeftFromPoint:origin];
        origin.y -= initialSize.size.height;
        //[[wc.window animator] setFrameOrigin:origin];   // Why setFrameOrigin and cascadeTopLeftFromPoint are not animated?
        initialSize.origin = origin;
        [[wc.window animator] setFrame:initialSize display:YES];
    }

    // This block should be invoked when all of the animations started above have completed or been cancelled.
    // For not to show the edit window till the duplication animation not finished
    [NSAnimationContext currentContext].completionHandler = ^{
        if (edit)
            [wc editDocument:self];
        else
            if (fullScreen)
                [wc.window toggleFullScreen:self];
    };

    [NSAnimationContext endGrouping];
Run Code Online (Sandbox Code Playgroud)

在这种情况下,完成块执行但不幸的是不等待窗口重新定位完成,而是立即打开窗口的编辑表并将它们一起移动。

最奇怪的是,在同一源文件中,同一类型的完成块上面的几行工作正常:-O

我在这里想念什么?

Mat*_*tie 5

这实际上不是一个错误,但是它使我绊倒了很多次。调用任何动画之前,必须设置完成处理程序。