CGPathQuery is used for calculating points along a CGPath, using Core Animation itself.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Classes
Demos/CGPathQueryDemoOSX
Vendor/CAAnimationBlocks
.gitignore
.gitmodules
LICENSE
Readme.md

Readme.md

CGPathQuery

CGPathQuery is used for calculating points along a CGPath. This is intended for composing points along the path as part of a more complex graphic (such as a ShapeLayer).

It works by using core animation itself to pre-calculate values along a given range, then can be 'queried' later. Specifically, it makes use of immediately calculating a collection of points by making the animation.speed zero then reading the presentationLayer's position upon completion. If a value in-between two precalculated points is queried, averaging is applied to determine the value.

The classes should be considered experimental 'proof-of-concept' code at this time.

####What CGPathQuery isn't for

  • Animating layers along a path. Core animation already does a great job of doing this by setting an animation.path property and an appropriate speed. This said, CGPathQuery could help if you're trying to animate the layer along a small partial segment of a path.

####References CGPathQuery uses the following techniques/libraries:

####Alternatives CGPathQuery was made to avoid replicating math at the expense of being a slightly less 'functional' solution. There's some other alternatives worth looking at:

####Warnings

  • CGPathQuery, at this time of writing, appears to work best for very simple paths - paths where the segments are equal in overall length. Be careful when using more complex paths - (e.g. from personal observation CGPathQuery can yield unexpected results when drawing long paths with ended with smaller rounded corners - where querying indicates 'bunching up' around the corners)

###TODO

  • Add usage documentation.
  • Make the pre-calculation step optional. So far I haven't yet found a way to retrieve animation values with core animation without causing a deadlock on the main thread.
  • Add rotation support. I've been able to grab the rotation angle in other demos from the presentationValue while layers are visible, but haven't been able to see it update in the current code.