Use cross fade transitions if reduce motion/prefer cross fade is enabled
This commit is contained in:
parent
7ac34efeab
commit
ab77ad89b4
|
@ -11,14 +11,23 @@ import UIKit
|
||||||
class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
|
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat && (transitionContext?.viewController(forKey: .from) as? SheetContainerViewController)?.dismissAnimationInitialVelocity == nil {
|
||||||
|
return 0.25
|
||||||
|
} else {
|
||||||
return 0.5
|
return 0.5
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
guard let fromVC = transitionContext.viewController(forKey: .from) as? SheetContainerViewController else {
|
guard let fromVC = transitionContext.viewController(forKey: .from) as? SheetContainerViewController else {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat && fromVC.dismissAnimationInitialVelocity == nil {
|
||||||
|
animateCrossFadeTransition(using: transitionContext)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fromVC.view.alpha = 1.0
|
fromVC.view.alpha = 1.0
|
||||||
fromVC.dimmingView.isHidden = true
|
fromVC.dimmingView.isHidden = true
|
||||||
|
|
||||||
|
@ -57,4 +66,19 @@ class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimat
|
||||||
animator.startAnimation()
|
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,14 +11,23 @@ import UIKit
|
||||||
class SheetContainerPresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class SheetContainerPresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
|
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat {
|
||||||
|
return 0.25
|
||||||
|
} else {
|
||||||
return 0.5
|
return 0.5
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
guard let toVC = transitionContext.viewController(forKey: .to) as? SheetContainerViewController else {
|
guard let toVC = transitionContext.viewController(forKey: .to) as? SheetContainerViewController else {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if UIAccessibility.prefersCrossFadeTransitionsBackwardsCompat {
|
||||||
|
animateCrossFadeTransition(using: transitionContext)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
toVC.dimmingView.isHidden = true
|
toVC.dimmingView.isHidden = true
|
||||||
|
|
||||||
let finalFrame = transitionContext.finalFrame(for: toVC)
|
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