10

iPhone で VoiceOver を使用して、ラベルの更新されたテキストが変更された場合に通知することはできますか?

これは、ARIA のライブ リージョンに似ています。

ありがとう。

4

2 に答える 2

21

VoiceOver で好きなテキストを読み上げることができます:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"Your text");

ラベルが更新されるとすぐにそのテキストをアナウンスする必要がある場合は、単純に を拡張しUILabelてメソッドをオーバーライドしますsetText

.h ファイル:

@interface UIVoicedLabel : UILabel {

}

@end

そしてその実装:

#import "UIVoicedLabel.h"

@implementation UIVoicedLabel

- (void) setText:(NSString *)text {
    // Set the text by calling the base class method.
    [super setText:text];
    // Announce the new text.
    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, text);
}

@end

これは私にとって完璧に機能しました:)

于 2011-06-20T07:43:58.087 に答える
2

これがSwift 4バージョンです

UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: "Your text")
于 2019-07-05T21:15:47.107 に答える