为 MKMapView 对象分配可访问性标识符
Assigning an accessibility identifier to an MKMapView object
我正在尝试为我正在使用的应用程序配置快照,它已经在英文版本中运行,但在本地化版本中我不知道如何为地图中的图钉分配可访问性标识符在 MKMapView 中,有人知道怎么做吗?
谢谢。
辅助功能标识符是将应用程序语言与 Xcode UI 测试分开的好方法。标识符来自 UIAccessibilityIdentification
,UIView
已经符合。但是,NSObject
和 MKAnnotation
都不符合协议。所以你必须自己设置一致性。
class Annotation: NSObject, MKAnnotation, UIAccessibilityIdentification {
let coordinate: CLLocationCoordinate2D
let title: String?
var accessibilityIdentifier: String?
init(title: String?, coordinate: CLLocationCoordinate2D) {
self.title = title
self.coordinate = coordinate
}
}
let coordinate = CLLocationCoordinate2DMake(40.703490, -73.987770)
let annotation = Annotation(title: "BeerMenus HQ", coordinate: coordinate)
annotation.accessibilityIdentifier = "Custom Identifier"
let mapView = MKMapView()
mapView.addAnnotation(annotation)
然后在测试中你可以通过otherElements
引用注解。
let app = XCUIApplication()
let annotation = app.maps.element.otherElements["Custom Identifier"]
annotation.tap()
我正在尝试为我正在使用的应用程序配置快照,它已经在英文版本中运行,但在本地化版本中我不知道如何为地图中的图钉分配可访问性标识符在 MKMapView 中,有人知道怎么做吗?
谢谢。
辅助功能标识符是将应用程序语言与 Xcode UI 测试分开的好方法。标识符来自 UIAccessibilityIdentification
,UIView
已经符合。但是,NSObject
和 MKAnnotation
都不符合协议。所以你必须自己设置一致性。
class Annotation: NSObject, MKAnnotation, UIAccessibilityIdentification {
let coordinate: CLLocationCoordinate2D
let title: String?
var accessibilityIdentifier: String?
init(title: String?, coordinate: CLLocationCoordinate2D) {
self.title = title
self.coordinate = coordinate
}
}
let coordinate = CLLocationCoordinate2DMake(40.703490, -73.987770)
let annotation = Annotation(title: "BeerMenus HQ", coordinate: coordinate)
annotation.accessibilityIdentifier = "Custom Identifier"
let mapView = MKMapView()
mapView.addAnnotation(annotation)
然后在测试中你可以通过otherElements
引用注解。
let app = XCUIApplication()
let annotation = app.maps.element.otherElements["Custom Identifier"]
annotation.tap()