完善任务流程、键盘适配与页面交互

This commit is contained in:
2026-07-10 15:56:15 +08:00
parent f88a85a807
commit ab5220e460
189 changed files with 16779 additions and 1038 deletions

View File

@ -6,24 +6,29 @@
import SnapKit
import UIKit
///
///
final class AllFunctionMenuCell: UICollectionViewCell {
static let reuseIdentifier = "AllFunctionMenuCell"
///
enum ActionStyle {
case none
case add
case remove
}
var onActionTap: (() -> Void)?
private let cardView = UIView()
private let contentStackView = UIStackView()
private let iconView = UIImageView()
private let titleLabel = UILabel()
private let actionButton = UIButton(type: .system)
private let actionImageView = UIImageView()
override var isHighlighted: Bool {
didSet {
cardView.alpha = isHighlighted ? 0.72 : 1
}
}
override init(frame: CGRect) {
super.init(frame: frame)
@ -35,26 +40,29 @@ final class AllFunctionMenuCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}
override func prepareForReuse() {
super.prepareForReuse()
onActionTap = nil
}
///
func apply(menu: HomeMenuItem, actionStyle: ActionStyle) {
iconView.image = UIImage(systemName: menu.iconName)
titleLabel.text = menu.title
accessibilityLabel = menu.title
switch actionStyle {
case .none:
actionButton.isHidden = true
actionImageView.isHidden = true
accessibilityTraits = []
accessibilityHint = nil
case .add:
actionButton.isHidden = false
actionButton.setImage(UIImage(systemName: "plus.circle.fill"), for: .normal)
actionButton.tintColor = AppColor.primary
actionImageView.isHidden = false
actionImageView.image = UIImage(systemName: "plus.circle.fill")
actionImageView.tintColor = AppColor.primary
accessibilityTraits = .button
accessibilityHint = "添加到常用应用"
case .remove:
actionButton.isHidden = false
actionButton.setImage(UIImage(systemName: "minus.circle.fill"), for: .normal)
actionButton.tintColor = AppColor.danger
actionImageView.isHidden = false
actionImageView.image = UIImage(systemName: "minus.circle.fill")
actionImageView.tintColor = AppColor.danger
accessibilityTraits = .button
accessibilityHint = "移出常用应用"
}
}
@ -78,11 +86,13 @@ final class AllFunctionMenuCell: UICollectionViewCell {
titleLabel.textAlignment = .center
titleLabel.numberOfLines = 2
actionButton.addTarget(self, action: #selector(actionTapped), for: .touchUpInside)
isAccessibilityElement = true
actionImageView.contentMode = .scaleAspectFit
actionImageView.isUserInteractionEnabled = false
contentView.addSubview(cardView)
cardView.addSubview(contentStackView)
cardView.addSubview(actionButton)
cardView.addSubview(actionImageView)
contentStackView.addArrangedSubview(iconView)
contentStackView.addArrangedSubview(titleLabel)
@ -96,13 +106,9 @@ final class AllFunctionMenuCell: UICollectionViewCell {
iconView.snp.makeConstraints { make in
make.width.height.equalTo(26)
}
actionButton.snp.makeConstraints { make in
actionImageView.snp.makeConstraints { make in
make.top.trailing.equalToSuperview().inset(AppSpacing.xxs)
make.width.height.equalTo(20)
}
}
@objc private func actionTapped() {
onActionTap?()
}
}