Alan Quatermain

The Tumblog of one Jim Dovey, iOS Software Chief Architect at Kobo in Toronto, Ontario.
He Twitters, he has an , and can occasionally be found on LinkedIn or Facebook.
If you have a query, you can ask it here.

This blog contains personal opinions, and is not endorsed by any company.

963253773
My question pertains more to object-oriented design in a way. I wanted to know your thoughts on replicating something the Photos app interface on the iPad. You have a grid of albums (AlbumsViewController) that can expand into a new grid of photos (PhotosViewController). The transition seems to be seamless. How would you do something like that (using something like AQGridView for the grids) while still keeping the view controllers de-coupled from one another?

AskerAnonymous

I’ve actually just implemented this in a new example project on github.

The ExpanderDemo project shows everything you need to do to have a new grid view expand out of a particular location. From the project’s README:

The expansion is triggered by calling the -expandCellsFromRect:ofView: method of ExpandingGridViewController. Before calling this, you must set the expanding grid view’s frame (so it can figure out what cells should be visible at what indices) and add it to a superview (so the passed rectangle can be mapped across). Afterward you should ensure that you call the new controller’s -viewDidAppear:. This last function implements the last part of the expansion algorithm.

In -expandCellsFromRect:ofView:, the controller converts the source rectangle into its own view’s coordinate space and caches it. It also goes through the grid view’s cell list and stores their existing frames ready to animate them later. Lastly, it sets its view’s background colour to clear. Then in -viewDidAppear: it first moves all the visible cells to the saved starting rectangle, then in an animation block it restores its background colour and moves the cells to their original positions.