你如何实现 UIAccessibility 协议?

How do you implement the UIAccessibility protocol?

"Accessibility Programming Guide For iOS" 状态:

Another way is to implement the isAccessibilityElement method of the UIAccessibility protocol in the implementation of your custom subclass. The following code snippet shows how to do this:

但是当我这样做的时候,如下代码:

class UITextLayerLabel : UIView, UIAccessibility {

XCode returns 我这个错误:

 [...] Use of undeclared type 'UIAccessibility'

我错过了什么?一个特定的进口? iOS10/XCode8 协议是否仍然可用?

正如指出的那样here, UIAccessibility is an informal protocol. For the difference between an informal protocol and a formal one, see here

基本上没有叫UIAccessibility的类型。实际上,UIView 已经符合 UIAccessibility。要使您的自定义视图可访问,只需覆盖以 accessibility.

开头的属性和方法

那么什么时候需要实施UIAccessibility?如所述 here

You can use UIAccessibilityElement to provide information about an icon or text image is not automatically accessible because it does not inherit from UIView (or UIControl ). A view that contains such nonview items creates an instance of UIAccessibilityElement to represent each item that needs to be accessible.