I am creating Hero animation like IOS app store click on the app to open detail page , I was able to create presentation animation without any issue but when I tried to dismiss the animation it shows a white background screen for some time, I tried all solution which is listed on stack overflow like adding subview only time, changing modalPresentationStyle to .fullscreen but could not get rid of the white background during dismissal Below is my sample code
let today = TodayDetailViewController()
today.transitioningDelegate = self
today.modalPresentationStyle = .fullScreen
guard let cell = collectionView.cellForItem(at: indexPath) else {
return;
}
let cellFrame = collectionView.convert(cell.frame, to: collectionView.superview)
modelTransition.originFrame = cellFrame;
present(today, animated: true, completion: nil);
-- Animation Transition Method
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
guard let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) else { return }
guard let toView = transitionContext.view(forKey: UITransitionContextViewKey.to) else { return }
let modalView: UIView = presenting ? toView : fromView
if(!presenting){
edgeLayoutConstraints?.constants(to: 0)
let animator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)
animator.addAnimations {
self.edgeLayoutConstraints?.match(to: self.originFrame,
container: containerView)
containerView.layoutIfNeeded()
modalView.layoutIfNeeded()
}
animator.addCompletion { position in
switch position {
case .end:
transitionContext.completeTransition(true)
default:
transitionContext.completeTransition(true)
}
}
animator.startAnimation()
}
else{
modalView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(toView)
edgeLayoutConstraints = NSEdgeLayoutConstraints(view: modalView,
container: containerView,
frame: originFrame)
edgeLayoutConstraints?.toggleConstraints(true)
containerView.layoutIfNeeded()
modalView.layoutIfNeeded()
let animator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)
animator.addAnimations {
self.edgeLayoutConstraints?.constants(to: 0)
containerView.layoutIfNeeded()
modalView.layoutIfNeeded()
}
animator.addCompletion { position in
switch position {
case .end:
transitionContext.completeTransition(true)
default:
transitionContext.completeTransition(true)
}
}
animator.startAnimation()
}