I'm doing a custom view controller transition in which the presented view controller, detailVC
, is scaled down when dismissed.
The procedure I chose is the following:
- snapshot
detailVC.view
, add it to the transition context'scontainerView
- hide
detailVC.view
- scale down the snapshot.
Here's the code:
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let detailVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as? DetailViewController
containerView.addSubview(detailVC.view)
detailVC.view.frame = containerView.frame
let detailVCSnapshot = detailVC.view.snapshotViewAfterScreenUpdates(true)
containerView.addSubview(detailVCSnapshot)
detailVC.view.hidden = true
...
}
Bizarrely, this works well on the iPad, but not on iPhone. On iPhone, detailVCSnapshot
is completely transparent.
Other answers (1, 2) recommend ensuring that the view has been drawn, but this is indeed the case as detailVC
is the currently visible view controller!
Any thoughts?