Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 2.47 KB

README.md

File metadata and controls

55 lines (40 loc) · 2.47 KB

CFAAction

Build Status

CFAAction is a wrapper around several common Core Animation animations that provides additional modularity and the ability to group and sequence actions.

Getting Started

CFAAction's should be treated like SKAction's, which means they are only run when they are submitted to a variant of -[CALayer runAction:].

To run an action that moves a layer 10 pixels to the right in 1 second, for example, you can do:

CFAAction *moveAction = [CFAAction moveByX:10 y:0 duration:1];
[self.view.layer runAction:growAnimation];

Completion blocks can be used to sequence animations:

CFAAction *rotateAction = [CFAAction rotateToAngle:M_PI duration:1];
CFAAction *growAnimation = [CFAAction resizeToHeight:400 duration:0.25];

[self.view.layer runAction:rotateAction completion:^{
	[self.view.layer runAction:growAnimation];
}];

But, so can +[CFAAction sequence:]:

CFAAction *rotateAction = [CFAAction rotateToAngle:M_PI duration:1];
CFAAction *growAnimation = [CFAAction resizeToHeight:400 duration:0.25];

[self.view.layer runAction:[CFAAction sequence:@[ rotateAction, growAnimation ]];

To run actions concurrently, there's +[CFAAction group:]:

CFAAction *rotateAction = [CFAAction rotateToAngle:M_PI duration:1];
CFAAction *scaleAnimation = [CFAAction scaleBy:-0.25 duration:0.25];
[self.view.layer runAction:[CFAAction group:@[ scaleAnimation, rotateAction ]]];

To perform a block or selector as an action, use [CFAAnimation runBlock:], [CFAAnimation runBlock:queue:], or [CFAAnimation performSelector:onTarget:]. When used in a group with a wait action, these can act as extensions for the total duration of the grouping. When used in a sequence, they can act as delays before or after the selector is performed for precision timing.

[self.planeLayer runAction:[CFAAction sequence:@[ bankAndRollAction, [CFAAction repeatAction:fireAction count:6] ]] completion:^{
		[self.enemy runAction:[CFAAction sequence:@[ dieAction, [CFAAction performSelector:@selector(die:) onTarget:self.enemy], [CFAAction waitForDuration:0.5] ]]];
}];

License

CFAAction is licensed under the MIT license. See LICENSE.md.

Contact

Follow me on Twitter @CodaFi_, or visit my website.