facebookarchive / pop

An extensible iOS and OS X animation library, useful for physics-based interactions.
Other
19.66k stars 2.88k forks source link

Animate CAGradientLayer properties #338

Closed sryze closed 8 years ago

sryze commented 8 years ago

Does POP support animating of CAGradientLayer properties like locations? Or do we have to resort to Core Animation for that?

I couldn't find constant definitions for any of CAGradientLayer-specific properties in the headers. Simply passing "locations" as the property name doesn't seem to work, I'm getting the following exception:

*** Terminating app due to uncaught exception 'Unsuported value', reason: 'Animating __NSArrayI values is not supported'
grp commented 8 years ago

They aren't supported using the built-in properties, but you can use a custom POPAnimatableProperty. I think there's a link in the readme for an example, but it's also documented in the header.

Note that Pop's animation model only works for fixed-dimension properties, so if you want to change the number of locations, that wouldn't be possible. One approach you could take is to add a CAAnimation for the locations, then scrub through the animation with Pop by setting the layer's speed to 0 and adjusting its timeOffset through a custom Pop animatable property. Another approach would be to model the property as going from 0 to 1, then compute the interpolated locations manually in the animatable property setter.