|
I'm working on the BucketList project, and I'm to the point of implementing the long press gesture. But the gesture isn't being picked up in the simulator or in preview. I tried adding 'print("Received long press")' to .onLongPressGesture, and nothing gets printed in the console for long presses, but 'print' statements in .onTapGesture are shown. This is where I disclose that I'm running Xcode 16 beta 3 on macOS 15 beta 3, so chances of this problem being related to that are not zero. :-) |
|
|
|
I tried a simple image with .onLongPressGesture attached, and with the action set to just toggle the color of the star. That works fine. So then I pulled out the MapReader block of code from the BucketList project, minus the ForEach loop, so it just has a single annotation, but that doesn't work. It displays the map and the annotation point, but a long press on the star doesn't do anything. Not sure what I'm missing. Any ideas? (I tried to post the whole ContentView.swift file, but it gets blocked as spam for some reason.)
|
|
I had the same question. For debugging on Simulator and Preview i add Now after drop a new pin — EditView sheet is presented immidiately |
|
I'm having the same issue with long press gesture not working in canvas or simulator. I'm on Xcode 16.0 general release. There are also people complaining about this in the Apple developer forums, so this is a known bug. Hopefully it gets fixed soon! |
|
I solved the issue using the simultaneous Gesture .simultaneousGesture(LongPressGesture(minimumDuration: 1).onEnded { _ in selectedPlace = location }) |
|
|
|
My guess is the Map's gestures take priority here so by using |
|
Thanks @cr34t1ve! Your solution works great. The simultaneousGesture doc says, "Use this method when you need to define and process a view specific gesture simultaneously with the same priority as the view’s existing gestures. " FWIW, I noticed using print statements that MapReader was triggering but LongPress wasn't. That seems to match what this is for too. I would have guessed events would have bubbled up like in JS. Guess not. |
SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.