Under the Bridge

CPAnimationSequence

Here is an excellent helper for putting together Core Animation sequences:

Declarative UIView animation sequences

…For our app, I wrote a component with which the above example could be written like this:

[[AnimationSequence sequenceWithSteps:

[AnimationStep for:0.25 do:^{ self.imageView.alpha = 0.0; }],

[AnimationStep for:0.25 do:^{ self.headline.alpha = 0.0; }],

[AnimationStep for:0.25 do:^{ self.content.alpha = 0.0; }],

[AnimationStep after:1.0 for:0.25 do:^{ self.headline.alpha = 1.0; }],

[AnimationStep for:0.25 do:^{ self.content.alpha = 1.0; }],

nil]

run];

Now this looks much more like a sequence! In addition, it drastically reduces boilerplate code, which has the nice side-effect that anything special stands out…

Very nice indeed compared to chained callbacks or nested blocks, yes? Code can be found on github to check it out.

(And also note reference to this older post for an approach along the same lines if you still need to be able to compile without blocks.)

h/t: @jakemarsh!

1
  • http://twitter.com/fascox Fabio Scognamiglio

    Great blog with precious content but the site is unreadable. A knock in the eye…