1
私はこのプロジェクトを最近ダウンロードし、最新の迅速な構文に変換しました。条件バインディングの初期設定には、 "UIView"ではなく、オプションの型が必要です
:ここlet containerView = transitionContext.containerView
は完全なコードです:私はUIViewの 『
エラーがライン上で発生している「結合条件付きの初期化子は、オプションの種類ではなく持っている必要があります』というエラーを取得し続ける理由を私は理解できません
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard
let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
let containerView = transitionContext.containerView
else {
return
}
containerView.insertSubview(toVC.view, belowSubview: fromVC.view)
let screenBounds = UIScreen.main.bounds
let bottomLeftCorner = CGPoint(x: 0, y: screenBounds.height)
let finalFrame = CGRect(origin: bottomLeftCorner, size: screenBounds.size)
UIView.animate(
withDuration: transitionDuration(using: transitionContext),
animations: {
fromVC.view.frame = finalFrame
},
completion: { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
)
}
ガードステートメントの 'let containerView = transitionContext.containerView'を' containerView.insertSubview(toVC.view、belowSubview:fromVC.view) 'の上に置いてください。 –