0

I have a UIScrollView in which I want to add a huge amount of subviews. Every picture is 256x256 pixels. The ContentSize of the ScrollView is 8.192 pixels, so this would be 32x32 images. I want to only load the UIImages / create the UIImagesViews I am currently seeing. I probably have to use scrollViewDidScroll and determine the correct position of that image via contentOffset. The Images are on a server and I load them asynchronously. The folder structure is "Images/Row/Column/row_column.jpg" Where Row and Column will be replaced by the actual number e.g. "Images/4/2/4_2.jpg"

I want to stick with UIScrollView, because it gives me more possibilities than a UICollectionView.

I hope you can guide me in the right direction.

smnk
  • 471
  • 1
  • 6
  • 25

2 Answers2

1

I think the direction you may want to look is implementing a UICollectionView with a UICollectionViewFlowLayout that responds to pinch-to-zoom gestures. That's the hard part. Then the easy part is implementing your datasource, which UICollectionView uses for lazy-loading of its cells (your images).

I haven't watched this video but a quick Google search pointed me to it:

https://www.youtube.com/watch?v=8vB2TMS2uhE

josefdlange
  • 455
  • 3
  • 7
  • Then again if you're expecting it to work more like a wall of pictures you can zoom in and out of perhaps it's not the best solution. You could probably think about the patterns that `UICollectionView` and `UITableView` implement -- data source and delegation -- to figure out a way that you lazily load your image views using `scrollViewDidScroll` – josefdlange Jan 30 '16 at 19:09
  • The Problem is that I want to add way more functionality like panning, turning, zooming, scrolling. Essentially it is going to be a fictional map. With navigational functions – smnk Jan 30 '16 at 23:18
  • See my comment and look into the design of `UITableViewDelegate`/`UITableViewDataSource` -- the patterns they follow are probably where you'll want to start. A table view is a subclass of a scrollview and essentially observes changes in the scrolling to determine which views it should ask its data source for and to paint in the content view. – josefdlange Jan 31 '16 at 20:32
1

I ended up writing a complete custom framework for my use case, which caches, and loads only the images I need.

I did not use a UICollectionView as supposed by josefdlange

Thank You for your help.

smnk
  • 471
  • 1
  • 6
  • 25