3

I am using the dragGesture in SwiftUI to develop my game. I am facing a problem with iOS Reachability Swipe Gesture. When user tries to swipe down at the very bottom of the device, iOS calls iOS reachability. I need to disable this iOS feature for my app. I checked this link:

Disable iOS Reachability Swipe Gesture in iOS game.

Below function seems to be the answer for UIKit:

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
    return [.bottom]
} 

How can I use this function and disable iOS Reachability Swipe Gesture in SwiftUI?

Bank
  • 67
  • 1
  • 8
  • Are you using the UIKit or SwiftUI lifecycle? – jnpdx Mar 05 '21 at 19:31
  • I am using the SwiftUI lifecycle. – Bank Mar 05 '21 at 19:34
  • Hm. That may be rough. My suspicion is that you'll have to subclass `UIHostingController` to override that property, which I guess you *could* do inside another `UIViewControllerRepresentable`, but that's much uglier than just doing it at the root level in your `SceneDelegate` – jnpdx Mar 05 '21 at 19:39
  • 1
    How to disable (UIKit) ONLY swipe-down (bottom) reachability gesture? – sabiland May 05 '22 at 06:12
  • 2
    Look at https://stackoverflow.com/a/61221343/12299030 with native SwiftUI modifier added. – Asperi Jul 07 '22 at 14:00

1 Answers1

0

As Asperi Mentioned. SwiftUI have answer for this in iOS 16+.

Apple documentation

in my case I just add

.defersSystemGestures(on: bottom)
Bank
  • 67
  • 1
  • 8