我正在创建像 IOS 应用商店这样的英雄动画,点击应用打开详细信息页面,我能够毫无问题地创建演示动画,但是当我尝试关闭动画时,它显示了一段时间的白色背景屏幕,我尝试了所有解决方案它列在堆栈溢出中,例如仅添加子视图,将 modalPresentationStyle 更改为 .fullscreen 但在解雇期间无法摆脱白色背景 下面是我的示例代码
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);
-- 动画过渡方法
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()
}