Questions tagged [draggesture]

61 questions
10
votes
2 answers

Interaction of DragGesture and ScrollView in SwiftUI

In an app I'm working on, there is a part that has, mostly, a "forward" navigation – tapping on buttons would display the next slide. However, a secondary "backward" navigation is also necessary. Here's the approach I've used: import SwiftUI struct…
Baglan
  • 1,057
  • 10
  • 23
6
votes
0 answers

SwiftUI view gets extensively re-rendered when moved causing stuttering

What is the best way to deal with SwiftUI is re-rendering an entire view that is moved using an DragGesture and the .offset() modifier: MyView().offset(x: drag.translation.width)? As soon as MyView() is a very large view, containing a huge amount of…
Leo
  • 1,508
  • 13
  • 27
6
votes
2 answers

SwiftUI drag gesture freezes with multi-touch

I am trying to drag a view in SwiftUI. The drag works perfectly until I place my second finger on screen, after that the drag stops and neither of the code blocks (onChanged, onEnded) gets called. But, when I again start dragging with a single…
SandeepAggarwal
  • 1,273
  • 3
  • 14
  • 38
5
votes
0 answers

SwiftUI DragGesture swallowed by ScrollView

I want to register a certain drag gesture on any SwiftUI view, including ScrollViews simultaneously with any other gestures (i.e. without influencing existing gestures). However, when adding a DragGesture on a ScrollView as follows, it seems like…
Mischa
  • 15,816
  • 8
  • 59
  • 117
5
votes
5 answers

SwiftUI: ScrollView that drags bottom sheet with it

I'm trying to create a SwiftUI Scrollview that drags its container like this: https://drive.google.com/file/d/1O92DgsVI1OjM1HEUXUwVywB8gcdShOP-/view?usp=sharing Many Apple apps use this (Apple Maps, Music, Wallet, etc) but I haven't found an easy…
blrsk
  • 185
  • 1
  • 4
  • 11
5
votes
3 answers

How to stop SwiftUI DragGesture from animating subviews

I'm building a custom modal and when I drag the modal, any subviews that have animation's attached, they animate while I'm dragging. How do I stop this from happening? I thought about passing down an @EnvironmentObject with a isDragging flag, but…
daihovey
  • 3,485
  • 13
  • 66
  • 110
5
votes
1 answer

Limit rectangle to screen edge on drag gesture

I'm just getting started with SwiftUI and I was hoping for the best way to tackle the issue of keeping this rectangle in the bounds of a screen during a drag gesture. Right now it goes off the edge until it reaches the middle of the square (I think…
Ross Moody
  • 773
  • 3
  • 16
4
votes
1 answer

SwiftUI DragGesture is freeze

I tried to do a resizable view with a gesture. The problem is that when I move my gesture object left or right the app will be freeze with 100% processor usage. It is the loop between two Text views. What did I do wrong, and how do I make this…
Nico
  • 51
  • 4
4
votes
2 answers

What is the best way to get Drag Velocity?

I was wondering how can one get DragGesture Velocity? I understand the formula works and how to manually get it but when I do so it is no where what Apple returns (at least some times its very different). I have the following code snippet struct…
Muhand Jumah
  • 1,726
  • 1
  • 11
  • 26
4
votes
1 answer

How to restrict drag gesture to particular frame only in swiftUI

I want to drag circle shape only within a frame horizontal. I try below code you can see shape work perfectly horizontal and also left side but when drag right side shape drag up to out of device frame. I check so many answer but did't work…
Ruchi Makadia
  • 1,005
  • 1
  • 7
  • 20
4
votes
2 answers

Adding Drag Gesture to image inside a ForEach in SwiftUI

I am currently developing an App shows a user his plant boxes and some measurements (like ground humidity, temperature etc) Each plant box has some plants inside it, which are being displayed in a detail view. I want the user to be able to drag one…
Tobilence
  • 115
  • 1
  • 6
3
votes
1 answer

SwiftUI DragGesture() get start location on screen

I want to make a view "swipeable", however this view only covers a small share of the whole screen. Doing: var body: some View { ZStack { Text("ABC") .gesture(DragGesture().onChanged(onChanged)) } } func…
user2161301
  • 674
  • 9
  • 22
3
votes
1 answer

How can I disable iOS Reachability Swipe Gesture in SwiftUI

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…
Bank
  • 67
  • 1
  • 8
2
votes
2 answers

How to define drag gesture in property on SwiftUI view

I cannot return DragGesture from computed property like below '_EndedGesture<_ChangedGesture>' to return type 'DragGesture' var dimDrag : DragGesture { DragGesture() .onChanged({ print("Dim…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
1
vote
2 answers

How can I keep my text within the confines of a frame

I have a draggable text and I have a red rectangle . I am trying to have that draggable text within that red rectangle and to only allow it to be dragged inside that rectangle . I have this code so far and it does everything that I need except the…
user1591668
  • 2,591
  • 5
  • 41
  • 84
1
2 3 4 5