Parallax Effect

A parallax effect is, as Wikipedia describes, a displacement or difference in the apparent position of an object viewed along two different lines of sight.  Checkout some cool samples!

For a project I'm working on, I needed such an effect for their iPad app.  As I normally do, I tried looking for available components, though the only references I found were pointing towards Cocos2D (OpenGL) which seemed a bit overkill just to have the parallax effect.

So I made my own implementation, based on a few UIScrollViews. Nothing extraordinary, but nevertheless a nice effect. This is the general idea:

  • disable all but 1 UIScrollView (main)
  • define the scrollratio of the other UIScrollViews (slaves)
  • implement the main UIScrollView delegate (especially scrollViewDidScroll) and adapt the slaves' UIScrollView contentPosition's as a factor of the main's contentPosition.

You can grab a copy of my sample project to see how I implemented it.