2021-04-28 09:02:34 +02:00
|
|
|
//
|
|
|
|
// ViewControllerAnimatedTransitioning.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-28.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
protocol ViewControllerAnimatedTransitioningDelegate: AnyObject {
|
|
|
|
var wantsInteractiveStart: Bool { get }
|
|
|
|
func animationEnded(_ transitionCompleted: Bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
class ViewControllerAnimatedTransitioning: NSObject {
|
|
|
|
|
|
|
|
let operation: UINavigationController.Operation
|
|
|
|
|
2021-07-14 14:28:41 +02:00
|
|
|
var transitionDuration: TimeInterval
|
2021-04-28 09:02:34 +02:00
|
|
|
var transitionContext: UIViewControllerContextTransitioning!
|
|
|
|
var isInteractive: Bool { return transitionContext.isInteractive }
|
|
|
|
|
|
|
|
weak var delegate: ViewControllerAnimatedTransitioningDelegate?
|
|
|
|
|
|
|
|
init(operation: UINavigationController.Operation) {
|
|
|
|
assert(operation != .none)
|
|
|
|
self.operation = operation
|
2021-07-14 14:28:41 +02:00
|
|
|
self.transitionDuration = 0.3
|
2021-04-28 09:02:34 +02:00
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - UIViewControllerAnimatedTransitioning
|
|
|
|
extension ViewControllerAnimatedTransitioning: UIViewControllerAnimatedTransitioning {
|
|
|
|
|
|
|
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
2021-07-14 14:28:41 +02:00
|
|
|
return transitionDuration
|
2021-04-28 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
|
|
|
self.transitionContext = transitionContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func animationEnded(_ transitionCompleted: Bool) {
|
|
|
|
delegate?.animationEnded(transitionCompleted)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - UIViewControllerInteractiveTransitioning
|
|
|
|
extension ViewControllerAnimatedTransitioning: UIViewControllerInteractiveTransitioning {
|
|
|
|
|
|
|
|
func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) {
|
|
|
|
self.transitionContext = transitionContext
|
|
|
|
}
|
|
|
|
|
|
|
|
var wantsInteractiveStart: Bool {
|
|
|
|
return delegate?.wantsInteractiveStart ?? false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|