2017-06-06 3 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

hereと指摘したように、UIAccessibilityは非公式プロトコルです。非公式プロトコルと正式プロトコルの違いについては、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.

関連する問題