iPhone で VoiceOver を使用して、ラベルの更新されたテキストが変更された場合に通知することはできますか?
これは、ARIA のライブ リージョンに似ています。
ありがとう。
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
これは私にとって完璧に機能しました:)
これがSwift 4バージョンです
UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: "Your text")