gpt4 book ai didi

swift - 为 MKMapView 对象分配可访问性标识符

转载 作者:可可西里 更新时间:2023-11-01 00:36:31 25 4
gpt4 key购买 nike

我正在尝试为我正在使用的应用程序配置快照,它已经在英文版本中运行,但在本地化版本中我​​不知道如何为 MKMapView 中 map 中的图钉分配可访问性标识符, 有人知道怎么做吗?

谢谢。

最佳答案

辅助功能标识符是将应用程序语言与 Xcode UI 测试分开的好方法。标识符来自UIAccessibilityIdentification UIView 已经符合。但是,NSObjectMKAnnotation 都不符合该协议(protocol)。所以你必须自己设置一致性。

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()

关于swift - 为 MKMapView 对象分配可访问性标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37794754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com