I have the following hierarchy: UIViewController -> UICollectionView -> UICollectionViewCell -> UIScrollView -> UIImageView -> UIImage
With this hierarchy, I can have working-well zooming capability. But when I am done zooming-in, and swipe in to the next image, I need the previous imageview to reset to its original scale.
My Attempt: I stored the current index in my collection into
self.currendIndex
and then tried getting the collection view cell and set its scrollview zooming like so in the scrollViewWillBeginDecelerating event inside the view controller
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
let indexPath = IndexPath(item: self.currendIndex, section: 0)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! ImageCollectionViewCell
DispatchQueue.main.async {
cell.scrollView.zoomScale = 1
cell.scrollView.contentOffset = CGPoint(x: 0, y: 0)
}
}
But it doesn't zoom it down, it just goes to the next element and then when I come back it is still with the zoom level.
How to fix it?
async. - sunkehappy