Someone Wrong on the Internet

April 2009 Archive:

2009-04-19 15:27

Implementing Pinch Zoom on the iPhone

I spent the weekend writing a very simple application that uses OpenGL ES on the iPhone to display a square with a picture (texture) on it. You can then use the traditional iPhone one-finger drag to move the picture around, and pinch in and out to zoom in and out on it.

Simple in concept, anyway, but execution, especially for someone new to iPhone development and very rusty at OpenGL development, was very difficult. I may have spent the better part of Saturday tracking down a bug due to a one letter typo in my code.

The major difficulty is that since I was developing the application strictly in OpenGL (as a base for a game I am working on), I couldn't take advantage of the iPhone's built-in libraries to handle anything. I had to develop the code for dragging (easy) and pinch zoom (less easy).

The way pinch zoom is implemented on the iPhone, if your pinch is on the right side of the picture, you zoom in on the right side of the picture. If your pinch is at the top side of the picture, you zoom in on the top of the picture. You can try this on the iPhone yourself, or make the jump to see screenshots and the code I wrote to implement this feature.

Read more 7 comments