MoviaBox/ShortPlay/Thirdparty/JXTransition/UIViewController+JXTransition.swift
2025-04-09 18:24:58 +08:00

128 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UIViewController+JXTransition.swift
// Test
//
// Created by on 2022/10/10.
//
import UIKit
// push
@objc public protocol JXViewControllerPushDelegate: NSObjectProtocol {
/// pushpush
@objc optional func pushToNextViewController()
/// push
@objc optional func viewControllerPushScrollBegan()
/// push
/// - Parameter progress: 0-1
@objc optional func viewControllerPushScrollUpdate(progress: CGFloat)
/// push
/// - Parameter finished: pushtruepush falsepush
@objc optional func viewControllerPushScrollEnded(finished: Bool)
}
// pop
@objc public protocol JXViewControllerPopDelegate: NSObjectProtocol {
@objc optional func viewControllerPopShouldScrollBegan() -> Bool
/// pop
@objc optional func viewControllerPopScrollBegan()
/// pop
/// - Parameter progress: 0-1
@objc optional func viewControllerPopScrollUpdate(progress: CGFloat)
/// pop
/// - Parameter finished: poptruepop falsepop
@objc optional func viewControllerPopScrollEnded(finished: Bool)
}
extension UIViewController {
// // MARK: -
// private static let onceToken = UUID().uuidString
// @objc public static func jxTransitionAwake() {
// DispatchQueue.once(token: onceToken) {
// let oriSels = ["viewDidAppear:",]
// for oriSel in oriSels {
// jx_swizzled_instanceMethod("jxGesture", oldClass: self, oldSelector: oriSel, newClass: self)
// }
// }
// }
//
// @objc func jxGesture_viewDidAppear(_ animated: Bool) {
// jxGesture_viewDidAppear(animated)
// }
}
extension UIViewController {
enum GestureTransitionType: Int {
///
case fullScreen
///
case edge
///
case disabled
}
fileprivate struct AssociatedKeys {
static var jxDelegateBridge: Int?
static var jx_gestureType: Int?
}
/**
*/
var jx_popGestureType: GestureTransitionType {
get {
guard let obj = objc_getAssociatedObject(self, &AssociatedKeys.jx_gestureType) as? GestureTransitionType else { return .fullScreen }
return obj
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.jx_gestureType, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
/**
*/
fileprivate var jx_delegateBridge: JXTransitionDelegateBridge {
get {
var bridge = objc_getAssociatedObject(self, &AssociatedKeys.jxDelegateBridge) as? JXTransitionDelegateBridge
if bridge == nil {
bridge = JXTransitionDelegateBridge()
objc_setAssociatedObject(self, &AssociatedKeys.jxDelegateBridge, bridge, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
return bridge!
}
}
var jx_pushDelegate: JXViewControllerPushDelegate? {
get {
return jx_delegateBridge.jx_pushDelegate
}
set {
jx_delegateBridge.jx_pushDelegate = newValue
}
}
var jx_popDelegate: JXViewControllerPopDelegate? {
get {
return jx_delegateBridge.jx_popDelegate
}
set {
jx_delegateBridge.jx_popDelegate = newValue
}
}
}