そのため、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 パディングをその関数にしたいと思います。誰もこれを行う方法を知っていますか?