Here's my situation. I am trying to replicate the iOS Photos App zooming transition from its collectionView (in ViewController A) to the detail view showing the full pictures in a pageviewcontroller (in ViewControler B). All is good except when I start to delete photos in ViewController B. What I want is the collectionView in ViewController A to reloadData() to update its cells because of the deletion before the ViewController B to ViewController A animation transition starts. I used the following method from UIViewControllerAnimatedTransitioning as follows below:
func animateTransition(using transitionContext: UIViewControllerContextTransitioning)
{
let duration = transitionDuration(using: transitionContext)
// fromViewController=ViewController B, toViewController=ViewController A
let fromViewController = transitionContext.viewController(forKey: .from)!
let toViewController = transitionContext.viewController(forKey: .to)!
let containerView = transitionContext.containerView
//trying to get the snapshot of the image cell after collectionView.reloadData()
let collectionViewToReload = toViewController.collectionView
collectionViewToReload.reloadData()
let cellOfInterest = collectionView?.cellForItem(at: indexPathOfInterest) as! PhotoCell
let imageView = cell.photoImageView
...
}
So, I am trying to get the snapshot of the final imageView layout after the transition animation completes. The thing is, when 'collectionViewToReload.reloadData()' is executed, somehow the 'cellOfInterest' returns nil. As such, is that another way to approach this problem?
Thanks to KMT to have edited your post, I would not have read it otherwise ! Please pay attention to such "details" in the future.
What is the dataStore of the collection view ?
Do you delete item in it when you delete in the collection view ?
Then, even no need for reload.
Here is a typical function for deleting (first item in that case); reload is commented out, as not needed:
@IBAction func deleteIt(_ sender: UIButton) {
items.remove(at: 0)
let theIndex = IndexPath(row: 0, section: 0)
collectionView.deleteItems(at: [theIndex])
// collectionView.reloadData()
}