2017-06-06 103 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.