For gesture-centric apps, it can be difficult to quickly and easily show how to perform specific gestures. Two handed gestures, like Loose Leafās ruler gesture, can be particularly difficult to describe. As I was making tutorial content for Loose Leaf, I quickly realized that showing dots for touch locations just isnāt enough.
Importantly, the shadows actually animate to match your hand ā notice the pinch gesture above actually animates theĀ pinch shadow slightly. Also in the code is a two finger āpeace signā shadow, perfect for a two finger pan. And also a single finger shadow for taps and single finger pan.
All of the code for the shadows isĀ open sourced and available atĀ https://github.com/adamwulf/ios-hand-shadows.
In order to create realistic shadows, I needed to start with professional quality hand silhouettes ā I purchased and usedĀ this file for the initial shadow shapes, and then worked to make then easily animatable.Ā Itās within the license for me to distribute this derivative work free of charge, but if it makes your inner-lawyer nervous you can always buy your own copy forĀ $1.
How it works
For the curious, hereās how I was able to make this work. First, i downloaded the shadow fileĀ as an .eps file, and I then converted that file into an svgĀ using this site. Next, I imported that svg file into PaintCode, which made it easy to export any of those hand paths as UIBezierPath code.
The interesting bit of code was interpolating between two different paths during the gesture, so that the wide open pinch could smoothly deform into the closed pinch. To do that, I edited the paths so that they both contained the same number of points.
Once the paths have theĀ point count, interpolating is easy āĀ use a smoothing number between 0 and 1, and calculate a weighted average of the two point locations ā thatās it!
The rest of the code helps display those paths on screen, manage multiple shadows on screen at a time, etc.
Enjoy!
Grab the code here! If you found this helpful, shares and tweets are always appreciated, and of course, support your local indie dev and check out Loose Leaf!