1

When using UIKit for touch events, you will get the UITouch which has the UITouch.force, UITouch.majorRadius

but When using SwiftUI, the dragGesture, or any Gesture, you won't get the UITouch, instead, you will get a value that has only touch coordinates x,y, but no force and majorRadius

how can get the force and the majorRadius in pure SwiftUI without using UIKit?

SwiftUI enter image description here

UIKit UIKit

Ziv Adler
  • 169
  • 2
  • 11
  • Gesture is gesture, touch is touch... they are different things. – Asperi Jul 20 '22 at 16:25
  • So how can I get the touch.force and touch.majorRadius in SwiftUI without UIkit? – Ziv Adler Jul 20 '22 at 16:38
  • Not today, there is no native API for that, so either defer transition to SwiftUI or try to use UIViewRepresentable as a bridge. – Asperi Jul 20 '22 at 16:40
  • UIViewRepresentable that's nice but I don't want UIkit in my app. My app is pure swiftui only – Ziv Adler Jul 20 '22 at 16:49
  • In which case you don't get those properties as they aren't available in SwiftUI (yet?). Can't have it both ways. – flanker Jul 20 '22 at 17:04
  • It is the same as cut left hand only because one is right-handed... but... it is your app ‍♂️. @ZivAdler... and by the way, you will not be able to get what you wanted because half of SwiftUI backend is still on UIKit engines. – Asperi Jul 20 '22 at 17:12
  • Is there something similar to force and majorRadius in pure SwiftUI? – Ziv Adler Jul 20 '22 at 17:27
  • 1
    As Asperi said, there is no SwiftUI API that registers force. – Yrb Jul 21 '22 at 20:13
  • @Asperi SwiftUI using UIKit on backend is encouraging. However, with UIViewRepresentable, a SwiftUI Drag gesture will block UITouch(s). Oddly, UITouch doesn't block a SwiftUI Drag. Weird. – Warren Stringer Sep 14 '22 at 00:02

0 Answers0