Skip to content

Commit

Permalink
Merge pull request Tencent#1036 from kimwjc/ToastAccessibility
Browse files Browse the repository at this point in the history
[fix][无障碍]修复在旁白开启状态下Toast内的信息无法被视障用户获取的问题
  • Loading branch information
MoLice authored Jun 30, 2020
2 parents 3c11f4f + 5d995e3 commit ea03de8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions QMUIKit/QMUIComponents/QMUITips.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ - (void)showTipWithText:(NSString *)text detailText:(NSString *)detailText hideA
} else if (delay > 0) {
[self hideAnimated:YES afterDelay:delay];
}

[self postAccessibilityAnnouncement:text detailText:detailText];
}

- (void)postAccessibilityAnnouncement:(NSString *)text detailText:(NSString *)detailText {
NSString *announcementString = nil;
if (text) {
announcementString = text;
}
if (detailText) {
announcementString = announcementString ? [text stringByAppendingFormat:@", %@", detailText] : detailText;
}
if (announcementString) {
// 发送一个让VoiceOver播报的Announcement,帮助视障用户获取toast内的信息,但是这个播报会被即时打断而不生效,所以在这里延时1秒发送此通知。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementString);
});
}
}

+ (NSTimeInterval)smartDelaySecondsForTipsText:(NSString *)text {
Expand Down

0 comments on commit ea03de8

Please sign in to comment.