this is about SwiftUI.
I have an object with a DragGesture attached to it that is positioned at the very bottom of the screen in iOS – just above the safe area with the app switcher handle. The drag gesture should only be triggered when dragging from inside of the object + the area of a couple of pixels around it, that’s expected. It correctly doesn’t get triggered while dragging from outside of the object (left, right, top side) but when I try to switch apps by swiping up on the home screen handle at the bottom of the screen the drag gesture gets triggered. Please see the code and the animation. How do I get rid of this behavior?
I searched for an answer to this everywhere but to no avail. I tried to specifically set the area that should respond to the gesture but also to no avail. Dragging up from the home screen handle does something that makes iOS think that after the finger leaves the safe area the user tapped the object triggering the gesture. Even though they never lifted the finger after touching the screen. The gesture shouldn’t be triggered by swiping up, it’s an unwanted behavior.
Thank you for your help.
import SwiftUI
struct ContentView: View {
@State private var offset = CGSize.zero
@State var color = Color.green
var body: some View {
Spacer()
Circle()
.fill(color)
.frame(width: 64, height: 64)
.offset(offset)
.gesture (
DragGesture(minimumDistance: 0)
.onChanged { value in
color = .red
offset = value.translation }
.onEnded { _ in
color = .green
offset = .zero
}
)
}
}
#Preview {
ContentView()
}```
Orbivox is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.