Add CYLTabBarController with a global scan entry, promote MainTabBarController to the window root after login, replace RouterPath-based navigation with AppNavigator, and fix Profile diffable cell reconfiguration crashes. Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.9 KiB
Swift
78 lines
2.9 KiB
Swift
//
|
||
// MainScanPlusButton.swift
|
||
// suixinkan
|
||
//
|
||
|
||
import CYLTabBarController
|
||
import UIKit
|
||
|
||
@MainActor
|
||
@objcMembers
|
||
/// 主 TabBar 中间扫码核销按钮,基于 CYLTabBarController 的 PlusButton 机制实现。
|
||
final class MainScanPlusButton: CYLPlusButton, CYLPlusButtonSubclassing {
|
||
|
||
/// 点击扫码按钮时的回调,由 `MainTabBarController` 注入。
|
||
static var onScanTap: (() -> Void)?
|
||
|
||
/// 构建中间扫码按钮实例,供 CYLTabBarController 注册使用。
|
||
static func plusButton() -> Any {
|
||
let button = MainScanPlusButton(type: .custom)
|
||
button.frame = CGRect(x: 0, y: 0, width: 70, height: 64)
|
||
button.configureAppearance()
|
||
button.addTarget(button, action: #selector(handleScanTap), for: .touchUpInside)
|
||
return button
|
||
}
|
||
|
||
/// 指定扫码按钮在 TabBar 中的视觉槽位(位于订单与数据之间)。
|
||
static func indexOfPlusButtonInTabBar() -> UInt {
|
||
2
|
||
}
|
||
|
||
/// 调整扫码按钮垂直位置,使其略微凸出 TabBar 顶部。
|
||
static func constantOfPlusButtonCenterYOffset(forTabBarHeight tabBarHeight: CGFloat) -> CGFloat {
|
||
-6
|
||
}
|
||
|
||
/// 配置圆形背景与扫码图标,对齐参考工程 CustomMainTabBarCenterAction。
|
||
private func configureAppearance() {
|
||
backgroundColor = .clear
|
||
|
||
let circleSize: CGFloat = 58
|
||
let circleView = UIView()
|
||
circleView.isUserInteractionEnabled = false
|
||
circleView.backgroundColor = AppDesign.primary
|
||
circleView.layer.cornerRadius = circleSize / 2
|
||
addSubview(circleView)
|
||
|
||
let symbolConfig = UIImage.SymbolConfiguration(pointSize: 30, weight: .bold)
|
||
let iconView = UIImageView(
|
||
image: UIImage(systemName: "qrcode.viewfinder", withConfiguration: symbolConfig)
|
||
)
|
||
iconView.tintColor = .white
|
||
iconView.contentMode = .scaleAspectFit
|
||
iconView.isUserInteractionEnabled = false
|
||
addSubview(iconView)
|
||
|
||
circleView.translatesAutoresizingMaskIntoConstraints = false
|
||
iconView.translatesAutoresizingMaskIntoConstraints = false
|
||
NSLayoutConstraint.activate([
|
||
circleView.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||
circleView.centerYAnchor.constraint(equalTo: centerYAnchor),
|
||
circleView.widthAnchor.constraint(equalToConstant: circleSize),
|
||
circleView.heightAnchor.constraint(equalToConstant: circleSize),
|
||
iconView.centerXAnchor.constraint(equalTo: circleView.centerXAnchor),
|
||
iconView.centerYAnchor.constraint(equalTo: circleView.centerYAnchor),
|
||
iconView.widthAnchor.constraint(equalToConstant: 30),
|
||
iconView.heightAnchor.constraint(equalToConstant: 30)
|
||
])
|
||
|
||
accessibilityLabel = "扫码核销"
|
||
accessibilityIdentifier = "main.scan"
|
||
}
|
||
|
||
/// 响应用户点击,触发全局扫码流程。
|
||
@objc private func handleScanTap() {
|
||
Self.onScanTap?()
|
||
}
|
||
}
|