CALayer 没有 AccessibilityIdentifier

CALayer has no AccessibilityIdentifier

我已经构建了一个创建 CAShapeLayer 对象的概念证明,并且我能够正确设置它的 AccessibilityLabel。但是,我无法设置 AccessibilityIdentifier(似乎 UIView 对象存在此 属性,但 CALayer 对象不存在?)。

有谁知道如何为 CALayer 对象访问它 - 或者它是否可能?

Alladinian 的上述建议非常有效:

"I haven't tried it in practice, but you could adopt UIAccessibilityIdentification protocol and implement accessibilityIdentifier if you have subclassed the CALayer or even adopt the protocol in an extension of CALayer and return its name for example."

class AccessibilityLayer: CALayer, UIAccessibilityIdentification {
    var accessibilityIdentifier: String?
}
let layer = AccessibilityLayer()
layer.accessibilityIdentifier = "MyAccessibilityID"

是这样的吗?