You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Xcode中Apple Accessibility Audit的elementDetection违规问题咨询

如何触发Xcode无障碍审计中的elementDetection(XCUIAccessibilityAuditTypeElementDetection)违规?

我正在研究Xcode里的Apple Accessibility Audit,完全搞不清XCUIAccessibilityAuditTypeElementDetection这类审计的工作逻辑。我的目标是构造特定元素,让无障碍审计能检测出该类型的违规,但试了几种方法都没成功:

  • 给自定义按钮添加了无名称的UIAccessibilityCustomAction,理论上应该触发elementDetection违规,但没生效
  • 创建了尺寸为0×0的不可见元素,将其isAccessibilityElement设为true,未触发违规
  • 设置了屏幕外元素并把isAccessibilityElement设为true,同样没成功

附上我写的自定义按钮代码:

class ProductCardView: UIButton {
    private let productImageView = UIImageView()
    private let productNameLabel = UILabel()
    private let productPriceLabel = UILabel()
    
    init() {
        super.init(frame: .zero)
        setupViews()
        setupAccessibility()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews() {
        productImageView.image = UIImage(named: "exampleImage")
        productNameLabel.text = "Product Name"
        productPriceLabel.text = "$99.99"
        
        addSubview(productImageView)
        addSubview(productNameLabel)
        addSubview(productPriceLabel)
        
        productImageView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(200)
        }
        
        productNameLabel.snp.makeConstraints { make in
            make.top.equalTo(productImageView.snp.bottom).offset(8)
            make.left.right.equalToSuperview().inset(8)
        }
        
        productPriceLabel.snp.makeConstraints { make in
            make.top.equalTo(productNameLabel.snp.bottom).offset(4)
            make.left.right.bottom.equalToSuperview().inset(8)
        }
    }
    
    private func setupAccessibility() {
        isAccessibilityElement = false
        productNameLabel.isAccessibilityElement = true
        productNameLabel.accessibilityLabel = nil
        let customAction = UIAccessibilityCustomAction(name: "", target: self, selector: #selector(handleCustomAction))
        accessibilityCustomActions = [customAction]
        
    }
    @objc private func handleCustomAction() -> Bool {
        print("Custom action performed.")
        return true
    }
}

内容的提问来源于stack exchange,提问作者Илья

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 02:05:14