I have been using the following method in my custom Animator class for a transition when a user selects a imageView in a cell of a tableViewController to a focus view showing the enlarged image. The imageView animates nicely from it's frame in the tableView to full screen and then back when I dismiss it.
This worked fine prior to iOS 13. But now when I use this animated transition on a modally presented tableViewController, the animation to the focus view works fine but when I dismiss the focus view to animate back to the tableViewController, the tableViewController is no longer there. It just shows the greyed out viewController that was underneath the modally presented tableViewController. I know the new modalPresentation default style is pageSheet but not sure why the top view controller prior to the animation disappears?
The animation still works fine for viewControllers that are not modally presented.
Wonder if this is a bug or if anybody has found a solution?
Here is my animateTransition function:
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// define variable to keep track of whether transitioning from or to
var presentingImage = false
// define containerView
let containerView = transitionContext.containerView
// get view controllers
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
// set the destination view controllers frame
toVC.view.frame = fromVC.view.frame
// create transition imageView
let imageView = UIImageView(image: image)
imageView.contentMode = .scaleAspectFill
imageView.frame = (fromDelegate == nil) ? CGRect() : fromDelegate!.imageWindowFrame()
imageView.clipsToBounds = true
// add imageView to containerView
containerView.addSubview(imageView)
// create from screen snapshot
fromDelegate!.transitionSetup(presentingImage: presentingImage)
toDelegate!.transitionSetup(presentingImage: presentingImage)
let fromSnapshot = fromVC.view.snapshotView(afterScreenUpdates: true)!
fromSnapshot.frame = fromVC.view.frame
containerView.addSubview(fromSnapshot)
// create to screen snapshot
let toSnapshot = toVC.view.snapshotView(afterScreenUpdates: true)!
toSnapshot.frame = fromVC.view.frame
containerView.addSubview(toSnapshot)
toSnapshot.alpha = 0
// bring the image view to the front and get the final frame
containerView.bringSubviewToFront(imageView)
let toFrame = (self.toDelegate == nil) ? CGRect() : self.toDelegate!.imageWindowFrame()
// animate change
UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: {
// set toSnapshot alpha to 1
toSnapshot.alpha = 1
// set imageView frame to toFrame
imageView.frame = toFrame
}, completion:{ (finished) in
// call transition cleanup for to and from delegate
self.toDelegate!.transitionCleanup(presentingImage: presentingImage)
self.fromDelegate!.transitionCleanup(presentingImage: presentingImage)
// remove transition views
imageView.removeFromSuperview()
fromSnapshot.removeFromSuperview()
toSnapshot.removeFromSuperview()
// complete transition
if !transitionContext.transitionWasCancelled {
containerView.addSubview(toVC.view)
}
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}