Reputation: 405
I'm new to SwiftUI. I'm showing a series of items in an HStack
. They don't need to move, but I'd like to highlight them as the user drags their finger over them, and change a separate view somewhere else to give more information about the highlighted item, without the user having to lift their finger. They should be able to slide back and forth and see the item under their finger highlight, and the separate view's content update.
In UIKit, I'd create a UIPanGestureRecognizer
, and as the gesture is recognized, get the correct view for the recognizer's location, set the view to be highlighted, set any other views to be un-highlighted, and update the detail view.
I can't figure out how to do this in SwiftUI, though. I don't want to drag anything around, I just want to get which view is underneath the user's finger as they slide it around.
Upvotes: 4
Views: 2780
Reputation: 3885
I guess something like this can help you:
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, World!")
Text("Hello, World!")
}
.gesture(
DragGesture()
.onChanged({ value in print(value) })
.onEnded({ _ in print("End")})
)
}
}
Upvotes: 1