I've implemented a custom transition between two view controllers in my iOS app and it worked fine with iOS 10, 11, and 12.
Now I want make it ready for iOS 13 using Xcode 11 beta 6 and iOS 13 beta 8, but the transition is stuck.
The custom transition should move the first view controller up and out of the screen and the second one from bottom up. But now it falls back to iOS13 default presentation style pageSheet
, just scales the first view controller down a little bit and adds a dimmed overlay. But the second view doesn't appear.
I've found that in the method animatePresentation(context: UIViewControllerContextTransitioning)
the context
doesn't return a 'from' view, so context.view(forKey: .from)
returns nil
.
What am I supposed to do without a 'from' view?
FlyUpTransition.swift
class FlyUpTransition: NSObject, UIViewControllerAnimatedTransitioning {
var mode: Mode = .present
enum Mode {
case present
case dismiss
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return TimeInterval(0.45)
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
switch mode {
case .present:
animatePresentation(context: transitionContext)
case .dismiss:
animateDismissal(context: transitionContext)
}
}
func animatePresentation(context: UIViewControllerContextTransitioning) {
guard let fromView = context.view(forKey: .from), let toView = context.view(forKey: .to) else { return }
...
}
func animateDismissal(context: UIViewControllerContextTransitioning) {
guard let fromView = context.view(forKey: .from), let toView = context.view(forKey: .to) else { return }
...
}
}