【问题标题】:NSAnimationContext setCompletionHandler not workingNSAnimationContext setCompletionHandler 不起作用
【发布时间】:2023-03-26 00:12:01
【问题描述】:

NSAnimationContext 中的setCompletionHandler 方法对我不起作用。我正在使用 Apple 文档中的代码:

    [NSAnimationContext setCompletionHandler:^{
   // This block will be invoked when all of the animations
   //  started below have completed or been cancelled.
    NSLog(@"All done!");

我有以下错误:没有已知的选择器'setCompletionHandler:'的类方法

当我查看此方法旁边的NSAnimationContext.h 文件时,有#if NS_BLOCKS_AVAILABLENS_AVAILABLE_MAC(10_7)。我的部署目标是“10.7”,但是我不知道如何检查NSBlocks 是否可用。还是问题出在其他地方?

【问题讨论】:

    标签: objective-c xcode macos objective-c-blocks


    【解决方案1】:

    文档中的示例代码有错误。 -setCompletionHandler: 方法是实例方法,而不是类方法。您需要在 [NSAnimationContext currentContext] 上调用它,而不是在类本身上:

    [[NSAnimationContext currentContext] setCompletionHandler:^{
       // This block will be invoked when all of the animations
       //  started below have completed or been cancelled.
        NSLog(@"All done!");
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      相关资源
      最近更新 更多