Monday, July 8, 2024
HomeiOS DevelopmentSwiping up from the underside of the display screen (to modify apps)...

Swiping up from the underside of the display screen (to modify apps) unintentionally triggers one other object’s DragGesture in SwiftUI, iOS


That is about SwiftUI.
I’ve an object with a DragGesture hooked up to it that’s positioned on the very backside of the display screen in iOS – simply above the secure space with the app switcher deal with. The drag gesture ought to solely be triggered when dragging from inside the article + the world of a few pixels round it, that is anticipated. It appropriately does not get triggered whereas dragging from outdoors of the article (left, proper, high aspect) however when I attempt to swap apps by swiping up on the house display screen deal with on the backside of the display screen the drag gesture will get triggered. Please see the code and the animation. How do I do away with this habits?

I looked for a solution to this in every single place however to no avail. I attempted to particularly set the world that ought to reply to the gesture but in addition to no avail. Dragging up from the house display screen deal with does one thing that makes iOS assume that after the finger leaves the secure space the person tapped the article triggering the gesture. Although they by no means lifted the finger after touching the display screen. The gesture should not be triggered by swiping up, it is an undesirable habits.
Thanks to your assist.

https://i.sstatic.internet/4hvgubwL.gif

import SwiftUI

struct ContentView: View {
    @State var offset = CGSize.zero
    @State var coloration = Coloration.inexperienced
    
    var physique: some View {
        Spacer()
        Circle()
            .fill(coloration)
            .body(width: 64, peak: 64)
            .offset(offset)
            .gesture (
                DragGesture(minimumDistance: 0)
                    .onChanged { worth in
                        coloration = .purple
                        offset = worth.translation }
                    .onEnded { _ in
                        coloration = .inexperienced
                        offset = .zero
                    }
            )
    }
}

#Preview {
    ContentView()
}```



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments