完善任务流程、键盘适配与页面交互
This commit is contained in:
@ -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?()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user