所以我使用 UIViewRepresentable 协议和以下函数渲染了一个 Mapbox 地图:
func makeUIView(context: Context) -> MGLMapView {
let map = MGLMapView()
DispatchQueue.main.async {
map.styleURL = self.mapStyle
map.delegate = context.coordinator
map.showsUserLocation = true
map.attributionButtonPosition = .topLeft
map.logoViewPosition = .topLeft
map.logoViewMargins.y = 15
map.logoViewMargins.x = 95
map.logoViewMargins.x = 12
map.attributionButtonMargins.x = 100
map.attributionButtonMargins.y = 15
self.configure(map)
}
return map
}
唯一的问题是,因为我对 y 边距的值进行了硬编码,所以跨多个设备的定位并不理想。我想使用 GeometryReader 来访问 safeAreaInsets,然后使 y 填充成为它的功能。有谁知道如何做到这一点?