swift - MapAnnotation 按钮操作不起作用(SwiftUI 2.0 地图)
问题描述
我只是想触摸地图注释,但按钮的操作不起作用。我试图弄清楚如何解决它,但到目前为止还没有。我想在不制作 UIKit 桥的情况下使用地图。
这是我的地图:
Map(coordinateRegion: $locationManager.currentLocation,
interactionModes: .all,
showsUserLocation: true,
userTrackingMode: $trackingMode,
annotationItems: $locationManager.annotations.wrappedValue) { location in
MapAnnotation(coordinate: location.coordinate, anchorPoint: CGPoint(x: 0.5, y: 0.5)) {
MapAnnotationView(name: location.title, image: Image("dog"))
}
}
这是我的 MapAnnotationView:
import SwiftUI
struct MapAnnotationView: View {
var name: String
var image: Image
@State var size: CGFloat = 20
var body: some View {
VStack {
Button(action: {
size = $size.wrappedValue == 20 ? 60 : 20
print("TAPPED =====>")
}, label: {
image
.resizable(capInsets: EdgeInsets(), resizingMode: .stretch)
.frame(width: $size.wrappedValue, height: $size.wrappedValue, alignment: .center)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 2))
Text(name)
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.primary)
})
}
.shadow(radius: 5)
}
}
解决方案
推荐阅读
- amazon-redshift - 将 UTC 转换为 CST 时 Redshift 中的时区问题
- push-notification - 如何在不打开新标签的情况下订阅在 amp 中发送通知?
- nativescript - Nativescript 和图像方向
- java - 数组中的循环与循环中的先前元素的比较
- java - 如何迭代java数组
- javascript - 字符串返回图片中每个字母的HTML搜索栏
- javascript - 如何在画布中增加/减小这个心形的大小?
- java - 转换 FieldInsnNode 的名称和信息
- php - 调用未定义的方法 DateTime::format 但 DateTime 正在工作
- java - Android - 如何使用 okhttp-retrofit 从保存的缓存中使特定 URL 无效/删除?