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
arrangedSubview
s - With a long press, add an overlay
UIView
as 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
alpha
from arrangedSubview
0 (setting hidden = true
will close the animation UIStackView
as if it were removed. - Add
tempView
to the top view (see 3) with the same starting frame asarrangedSubview
- Drag
tempView
up or down and insert / delete the actual arrangedSubview
at the calculated index according to the position tempView
. - Listen when a long press
state
is equal .Ended
and set arrangedSubview.alpha = 1
and 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?
source
share