objective-c - 为什么 NSAnimationContext completionHandler 不起作用(有时)?

标签 objective-c completionhandler nsanimationcontext


    // 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];

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

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

我在这里错过了什么?

最佳答案

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

关于objective-c - 为什么 NSAnimationContext completionHandler 不起作用(有时)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863297/

相关文章:

ios - Alamofire 和 completionHandler 的使用

android - 具有多个参数的 Kotlin 补全

cocoa - 减慢或暂停 NSAnimationContext

objective-c - 围绕中心旋转 NSView

iphone - 如何在iPhone应用程序中播放闹钟音乐?

ios - 替换 NSMutableArray 中出现的字符串只工作一次

ios - 将 NSMutableArray 设置为 NSDictionary - Objective C

firebase - 当一个函数需要前一个函数的值时,用于 Firebase 实时数据库查找的完成处理程序

ios - 如何在其他类 objective-c 中获取循环值