釣魚術
swift
swiftui
.onLongPressGesture { //do sth. }
.actionSheet(isPresented: $事件發生狀態布林變數) { ... }
struct MapView: View {
@State private var isLongPressed = false
@StateObject private var viewModel = FishingLocationModel()
var body: some View {
ZStack(alignment: .topTrailing) {
Map(coordinateRegion: $viewModel.region, showsUserLocation: true)
.edgesIgnoringSafeArea(.all)
.tint(.green)
.gesture(DragGesture())
.onLongPressGesture {
isLongPressed.toggle()
}.actionSheet(isPresented: $isLongPressed) {
ActionSheet(title: Text("新增私房釣點嗎?"),
message: nil,
buttons: [
.default(Text("新增釣點")) {
// Yes
},
.cancel()
])
}
LocationButton(.currentLocation) {
viewModel.requestAllowOnceLocationPermission()
}
.foregroundColor(.white)
.cornerRadius(15)
.labelStyle(.iconOnly)
.symbolVariant(.fill)
.padding(10)
}
}
}