I recently downloaded this project and converted it to the latest swift syntax. I can't understand why I continue to get the error "Initializer for conditional binding must have Optional type, not "UIView"
Error is occuring on line:
let containerView = transitionContext.containerView
Here is the full code:
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.containerViewout of the guard statement and put it abovecontainerView.insertSubview(toVC.view, belowSubview: fromVC.view)- Leo Dabus