问题
I'm trying to get some advice on how to go about implementing the same sort of "drag to reorder" behavior found on a UITableView but on a UIStackView.
So far this is what I'm thinking:
- Add a long press gesture recognizer to each of the
arrangedSubviews - On long press, add an overlay
UIViewas a subview to the main view and that fills the entire main view. This overlay view will act as a "canvas" of sorts as I'm dragging the temporary "reorder" view—we'll call this thetempView— around (more on that in 4) - Set the
alphaof thearrangedSubviewto 0 (settinghidden = truewould result in theUIStackViewanimating closing in as if it were removed. - Add a
tempViewto the overlay view (see 3) with the same initial frame as thearrangedSubview - Drag the
tempViewup or down and insert/remove the actualarrangedSubviewat a calculated index based on the position of thetempView. - Listen for when the long press
stateis.Endedand set thearrangedSubview.alpha = 1and remove the overlay view from the main view.
Any suggestions? Any glaring holes that anyone sees? What would you change? What direction would you go to accomplish this?
回答1:
I've created a custom control to solve this problem that can be found here.
Please see my last comment on the question post regarding known issues and future updates.
来源:https://stackoverflow.com/questions/33165079/uistackview-drag-to-reorder-arranged-subviews