2017-06-06 72 views
1

的 “辅助功能编程指南对于iOS” 规定:你如何实现UIAccessibility协议?

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返回我这个错误:

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

我错过了什么?具体的进口?该协议仍可用于iOS 10/XCode8吗?

+0

如果你的类继承的UIView,您自动具有被访问,因为UIView的符合这种非正式协议UIAccessibility协议的方法。不要在你的例子中指定协议,它应该像魅力一样工作。 –

回答

3

如指出hereUIAccessibility是一个非正式协议。有关非正式协议与正式协议之间的区别,请参见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.