From 1fdda914e0af473513982ba0a1c014dc2166eb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 3 Jun 2016 14:43:40 -0700 Subject: [PATCH] [ios] Corrected annotation view accessibility frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrected the accessibility frames of annotation views to match the views’ bounds instead of the bounds of the default annotation image (which could be empty if no default GL point annotation has been added). Fixes #5038. --- platform/ios/src/MGLMapView.mm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index cc2f7c35186..ee4346f27b5 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -98,6 +98,9 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) { /// Distance from the callout’s anchor point to the annotation it points to. const CGFloat MGLAnnotationImagePaddingForCallout = 1; +/// Minimum size of an annotation’s accessibility element. +const CGSize MGLAnnotationAccessibilityElementMinimumSize = CGSizeMake(10, 10); + /// Unique identifier representing a single annotation in mbgl. typedef uint32_t MGLAnnotationTag; @@ -2025,8 +2028,22 @@ - (id)accessibilityElementAtIndex:(NSInteger)index } // Update the accessibility element. - MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag]; - CGRect annotationFrame = [self frameOfImage:annotationImage.image centeredAtCoordinate:annotation.coordinate]; + MGLAnnotationView *annotationView = annotationContext.annotationView; + CGRect annotationFrame; + if (annotationView && annotationView.superview) + { + annotationFrame = [self convertRect:annotationView.bounds fromView:annotationView]; + } + else + { + MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag]; + annotationFrame = [self frameOfImage:annotationImage.image centeredAtCoordinate:annotation.coordinate]; + } + CGPoint annotationFrameCenter = CGPointMake(CGRectGetMidX(annotationFrame), CGRectGetMidY(annotationFrame)); + CGRect minimumFrame = CGRectInset({ annotationFrameCenter, CGSizeZero }, + -MGLAnnotationAccessibilityElementMinimumSize.width / 2, + -MGLAnnotationAccessibilityElementMinimumSize.height / 2); + annotationFrame = CGRectUnion(annotationFrame, minimumFrame); CGRect screenRect = UIAccessibilityConvertFrameToScreenCoordinates(annotationFrame, self); annotationContext.accessibilityElement.accessibilityFrame = screenRect; annotationContext.accessibilityElement.accessibilityHint = NSLocalizedStringWithDefaultValue(@"ANNOTATION_A11Y_HINT", nil, nil, @"Shows more info", @"Accessibility hint");