Reset zoom scale upon leaving cell

I have a UICollectionView child controller embedded in a container view to serve as a photo gallery. I have put a scrollview into the collection view cell and then layered on an imageview. Everything works fine. I can zoom in the cell, but when I move to the edge, the underlying collectionview scrollview takes over and I move to a new page. That's what I want, but I also want to reset the zoom scale (to 1.0) of the cell I just letf. Any suggestions as to how to do this?


zooming the cell in the collectionview cell:

import UIKit


class PlantPhotoCell: UICollectionViewCell, UIScrollViewDelegate {

@IBOutlet weak var imageView: UIImageView!

@IBOutlet weak var scrollView: UIScrollView!


override func awakeFromNib() {

self.scrollView.minimumZoomScale = 1.0

self.scrollView.maximumZoomScale = 4.0

self.scrollView.delegate = self

}


func viewForZooming(in scrollView: UIScrollView) -> UIView? {

return self.imageView

}


}

Cell definition and paging (Paging turned on in Storyboard):

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath

) -> UICollectionViewCell {

let cell = collectionView

.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PlantPhotoCell

let image = plantImgArray[indexPath.item]

cell.imageView.image = image

cell.imageView.layer.borderColor = UIColor.white.cgColor

cell.imageView.layer.borderWidth = 6

let title1 = UILabel(frame: CGRect(x: 0, y: cell.bounds.size.height - 20, width: cell.bounds.size.width, height:20))

let label = plantDesc[indexPath.item]

title1.text = label

title1.font = UIFont(name: "AvenirNextCondensed-Medium", size: 20)!

title1.backgroundColor = .white

title1.textAlignment = .center

cell.contentView.addSubview(title1)

return cell

}

override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {

let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)

pageControl.currentPage = Int(pageNumber)

}


Thanks for suggestions.

Replies

Still no answer?
1 year old thread, but maybe  ERGfrombeverly shores is still listening …

Did you try to implement zoomOut for the specific cell image in

Code Block
optional func scrollViewDidScroll(_ scrollView: UIScrollView)