@@ -89,25 +89,54 @@ final class NavigationTransitionAnimatorProvider: NSObject, UIViewControllerAnim
8989 )
9090 cachedAnimators [ ObjectIdentifier ( transitionContext) ] = animator
9191
92+ let container = transitionContext. containerView
93+ guard
94+ let fromUIView = transitionContext. view ( forKey: . from) ,
95+ let toUIView = transitionContext. view ( forKey: . to)
96+ else {
97+ return animator
98+ }
99+
100+ fromUIView. isUserInteractionEnabled = false
101+ toUIView. isUserInteractionEnabled = false
102+
92103 switch transition. handler {
93104 case . transient( let handler) :
94- if let ( fromView, toView) = transientViews ( for: handler, animator: animator, context: transitionContext) {
95- fromView. setUIViewProperties ( to: \. initial)
96- animator. addAnimations { fromView. setUIViewProperties ( to: \. animation) }
97- animator. addCompletion { _ in fromView. setUIViewProperties ( to: \. completion) }
98-
99- toView. setUIViewProperties ( to: \. initial)
100- animator. addAnimations { toView. setUIViewProperties ( to: \. animation) }
101- animator. addCompletion { _ in toView. setUIViewProperties ( to: \. completion) }
105+ if let ( fromView, toView) = transientViews (
106+ for: handler,
107+ animator: animator,
108+ context: ( container, fromUIView, toUIView)
109+ ) {
110+ for view in [ fromView, toView] {
111+ view. setUIViewProperties ( to: \. initial)
112+ animator. addAnimations { view. setUIViewProperties ( to: \. animation) }
113+ animator. addCompletion { _ in
114+ if transitionContext. transitionWasCancelled {
115+ view. resetUIViewProperties ( )
116+ } else {
117+ view. setUIViewProperties ( to: \. completion)
118+ }
119+ }
120+ }
102121 }
103122 case . primitive( let handler) :
104123 handler ( animator, operation, transitionContext)
105124 }
106125
107126 animator. addCompletion { _ in
108127 transitionContext. completeTransition ( !transitionContext. transitionWasCancelled)
109- transitionContext. view ( forKey: . from) ? . isUserInteractionEnabled = true
110- transitionContext. view ( forKey: . to) ? . isUserInteractionEnabled = true
128+
129+ fromUIView. isUserInteractionEnabled = true
130+ toUIView. isUserInteractionEnabled = true
131+
132+ // iOS 16 workaround to nudge views into becoming responsive after transition
133+ if transitionContext. transitionWasCancelled {
134+ fromUIView. removeFromSuperview ( )
135+ container. addSubview ( fromUIView)
136+ } else {
137+ toUIView. removeFromSuperview ( )
138+ container. addSubview ( toUIView)
139+ }
111140 }
112141
113142 return animator
@@ -116,19 +145,10 @@ final class NavigationTransitionAnimatorProvider: NSObject, UIViewControllerAnim
116145 private func transientViews(
117146 for handler: AnyNavigationTransition . TransientHandler ,
118147 animator: Animator ,
119- context: UIViewControllerContextTransitioning
148+ context: ( container : UIView , fromUIView : UIView , toUIView : UIView )
120149 ) -> ( fromView: AnimatorTransientView , toView: AnimatorTransientView ) ? {
121- guard
122- let fromUIView = context. view ( forKey: . from) ,
123- let toUIView = context. view ( forKey: . to)
124- else {
125- return nil
126- }
127-
128- fromUIView. isUserInteractionEnabled = false
129- toUIView. isUserInteractionEnabled = false
150+ let ( container, fromUIView, toUIView) = context
130151
131- let container = context. containerView
132152 switch operation {
133153 case . push:
134154 container. insertSubview ( toUIView, aboveSubview: fromUIView)
@@ -141,6 +161,6 @@ final class NavigationTransitionAnimatorProvider: NSObject, UIViewControllerAnim
141161
142162 handler ( fromView, toView, operation, container)
143163
144- return ( fromView: fromView , toView : toView)
164+ return ( fromView, toView)
145165 }
146166}
0 commit comments