Things you should realize
- To move a view, you can either modify its position or offset
- if we design to move its offset, we need something to store its offset, which is a value that can store the offset's x and y position, in this case we use
CGSize
- In the view you want to move, use
.gesture(DragGesture)
to let your view respond to your drag
- you can access the offset value caused by dragging using two modifier
.onChanged
and .onEnded
- The view's current offset should be equal to Firstly: the offset that's already existed before the dragging happens) + the drag offset caused by the current dragging