这个代码在objective-c中意味着什么?

水月年*_*月年华 1 iphone objective-c caanimation

[CATransaction withAnimationSpeed:1.0 :^ {
            if(newMultiplier > 100)
                fillLayer.backgroundColor = ColRGBA(1, 1, 0, 0.2);
            else
                fillLayer.backgroundColor = ColRGBA(0, 0, 0, 0);
        }];
Run Code Online (Sandbox Code Playgroud)

^ {}是什么意思?为什么要用这个符号.

Bol*_*ock 5

这被称为.它们与其他语言中的匿名函数类似,因为您使用它们来运行代码块作为其他一些例程(在您的情况下是动画)的一部分.当您不想在类中创建一次性使用方法时,块非常有用,因此您可以将其选择器传递给Objective-C方法,例如performSelector:.

^是块的符号.在中的代码{ }的行为就像在一个方法的代码{ }块.

某些块具有与C函数类似指定的参数:

^(int a, int b) {
    NSLog(@"a + b = %d", a + b);
}
Run Code Online (Sandbox Code Playgroud)

在您给定的代码中,^ {}是相同的^(void) {},即块不带任何参数.