【发布时间】:2023-01-16 03:08:43
【问题描述】:
我正在使用 Swift 的 MapKit 和自定义注释在地图上放置图钉。自定义注释是 ZStacks,它创建一个带有半径的引脚。下面的getNearbyEvents 函数返回Place 的列表。
Map(coordinateRegion: $viewModel.region,
showsUserLocation: true,
annotationItems: getNearbyEvents()
) {
place in
MapAnnotation(coordinate:place.coordinate) {
ZStack {
Circle()
.stroke(Color.black, lineWidth: 3)
.frame(width:160, height:160)
.opacity(0.6)
Circle()
.fill(Color("AccentColor"))
.opacity(0.2)
.frame(width:160, height:160)
Image("MapPin")
.resizable()
.frame(width: 50, height: 50, alignment: .center)
}
}
}
在 SwiftUI 画布中使用地图预览时,我可以四处平移,体验非常流畅。除了一些闪烁之外,注释始终可见并且效果很好。但是,当我在我的设备上构建应用程序时,地图在平移时将不再显示任何注释。在地图停止之前,他们都看不见了。有什么办法可以防止这种行为?我希望注释始终可见。
【问题讨论】:
-
在 ZStack 上尝试 .compositingGroup 或 .drawingGroup 修饰符。
-
@Asperi 不幸的是,这些修改器都不起作用。我尝试了
.compositingGroup()、.drawingGroup(),然后以两种顺序组合尝试。没有配置修复平移问题。.drawingGroup()修饰符还导致自定义注释的边缘略有裁剪。