Use cross fade transitions if reduce motion/prefer cross fade is enabled
This commit is contained in:
parent
7ac34efeab
commit
ab77ad89b4
|
@ -11,7 +11,11 @@ import UIKit
|
|||
class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return 0.5
|
||||
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat && (transitionContext?.viewController(forKey: .from) as? SheetContainerViewController)?.dismissAnimationInitialVelocity == nil {
|
||||
return 0.25
|
||||
} else {
|
||||
return 0.5
|
||||
}
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
|
@ -19,6 +23,11 @@ class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimat
|
|||
fatalError()
|
||||
}
|
||||
|
||||
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat && fromVC.dismissAnimationInitialVelocity == nil {
|
||||
animateCrossFadeTransition(using: transitionContext)
|
||||
return
|
||||
}
|
||||
|
||||
fromVC.view.alpha = 1.0
|
||||
fromVC.dimmingView.isHidden = true
|
||||
|
||||
|
@ -57,4 +66,19 @@ class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimat
|
|||
animator.startAnimation()
|
||||
}
|
||||
|
||||
func animateCrossFadeTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let fromVC = transitionContext.viewController(forKey: .from) as? SheetContainerViewController else {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
transitionContext.containerView.addSubview(fromVC.view)
|
||||
|
||||
let duration = transitionDuration(using: transitionContext)
|
||||
UIView.animate(withDuration: duration) {
|
||||
fromVC.view.alpha = 0
|
||||
} completion: { (finished) in
|
||||
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,11 @@ import UIKit
|
|||
class SheetContainerPresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return 0.5
|
||||
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat {
|
||||
return 0.25
|
||||
} else {
|
||||
return 0.5
|
||||
}
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
|
@ -19,6 +23,11 @@ class SheetContainerPresentationAnimationController: NSObject, UIViewControllerA
|
|||
fatalError()
|
||||
}
|
||||
|
||||
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat {
|
||||
animateCrossFadeTransition(using: transitionContext)
|
||||
return
|
||||
}
|
||||
|
||||
toVC.dimmingView.isHidden = true
|
||||
|
||||
let finalFrame = transitionContext.finalFrame(for: toVC)
|
||||
|
@ -56,4 +65,22 @@ class SheetContainerPresentationAnimationController: NSObject, UIViewControllerA
|
|||
|
||||
}
|
||||
|
||||
func animateCrossFadeTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let toVC = transitionContext.viewController(forKey: .to) as? SheetContainerViewController else {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
transitionContext.containerView.addSubview(toVC.view)
|
||||
|
||||
toVC.view.alpha = 0
|
||||
|
||||
let duration = transitionDuration(using: transitionContext)
|
||||
UIView.animate(withDuration: duration) {
|
||||
toVC.view.alpha = 1
|
||||
} completion: { (finished) in
|
||||
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Shadowfacts on 9/12/20.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIAccessibility {
|
||||
static var prefersCrossFadeTransitionsBackwardsCompat: Bool {
|
||||
if #available(iOS 14.0, *) {
|
||||
return prefersCrossFadeTransitions
|
||||
} else {
|
||||
return isReduceMotionEnabled
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue