Reputation: 85
I've been trying to think about the best way to implement this, and I've come to the conclusion that it may be possible with UIPageViewControllers. I would like to create a grid/map where I would be able to swipe through each coordinate. Below is a crudely drawn image of the concept -
I can implement the UIPageViewController Scrolling horizontally or vertically but my question is it possible to do it as if I'm traversing a grid with a 2 dimensional array. Is there some sort of library that I can use as an example as to how to do this? Any help would be appreciated.
Upvotes: 1
Views: 239
Reputation: 101
You can use 4 page view controllers, a top level one and then one for each column. Then you would put each "column" page view controllers to the top level. The top level guy would scroll horizontally, the columns would scroll vertically.
As for making it traverse a 2D array, you would pass the 1D "column" arrays to the "column" page view delegates. Inside the delegate, you would just use the 1D array as normal.
Upvotes: 1
Reputation: 131436
It seems to me that making the page view controller scroll horizontally or vertically is the much harder problem here. Page view controllers are designed to scroll left to right, and not intended to manage a grid of pages. Getting them to handle that correctly seems like it would be difficult or impossible to me.
As for fetching your pages, that seems like the easy part.
Simply track row/column numbers. Then map from 2-dimensional coordinates to a 1-dimensional array (The array of pages registered to the page view controller.)
index = column * rows_per_column + row;
A collection view set up in a grid might be a better choice (Adjusted so it fills the screen with one cell at a time.) Collection views are intended to handle grids of cells, among other layouts.
Upvotes: 0