UIStackView - drag and drop to reorder stacked objects?

I am trying to get some tips on how to implement the similar drag & drop behavior found on UITableView, but on UIStackView.

So far this is what I'm thinking of:

  • Add a long gesture recognizer for each of arrangedSubviews
  • With a long press, add an overlay UIViewas a subview of the main view and fill in the entire main view. This overlay view will act as a kind of “canvas” as I drag the temporary “reorder” view - we will call it tempView- around (more on this in 4)
  • Set alphafrom arrangedSubview0 (setting hidden = truewill close the animation UIStackViewas if it were removed.
  • Add tempViewto the top view (see 3) with the same starting frame asarrangedSubview
  • Drag tempViewup or down and insert / delete the actual arrangedSubviewat the calculated index according to the position tempView.
  • Listen when a long press stateis equal .Endedand set arrangedSubview.alpha = 1and remove the top view from the main view.

Any suggestions? Any obvious holes that anyone sees? What would you change? What direction would you take for this?

+4
source share
1 answer

, .

, .

+3

Source: https://habr.com/ru/post/1611893/


All Articles