Reputation: 110
I am having an "recycling like" issue on the iOs project I am working on. (I am saying a recycling like issue because it makes me think about recycling issue I had on Android projects).
I have a UICollectionView, with UICollectionViewCell. Each UICollectionViewCell contains a UIScrollView and a UIImageView inside it, in order to be able to zoom / pan the UIImageView.
The issue I am having is that when I zoom a UIImageView (let's call this UIImageView Bob) and then scroll the UICollectionView in a way that Bob is not visible on the screen, and then scroll back the UICollectionView so Bob is visible, sometimes the zoom is applied to another UICollectionCellView of the UICollectionView and Bob is not zoomed anymore, and sometimes Bob is correctly zoomed.
Any idea on what the issue could be ?
Thanks
Upvotes: 1
Views: 1198
Reputation: 7031
The UICollectionView datasource delegate recycles cell views to improve performance. So if you had a cell with imageView1 zoom at 2.0 and lets say a cell with imageView15 gets rendered, UICollectionView will attempt to recycle the cell with imageView1 again with zoom at 2.0. What you need to do is reset the zoom every time a cell is rendered in this function - collectionView:cellForItemAtIndexPath:
If you want it to remember the zoom, the easiest way is to create a NSMutableArray and store the zoom as NSNumbers every time
- collectionView:didEndDisplayingCell:forItemAtIndexPath:
is called. Then, when - collectionView:cellForItemAtIndexPath:
is called, load the zoom from the array.
Upvotes: 3