Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIStackView - drag to reorder arranged subviews?

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:

  1. Add a long press gesture recognizer to each of the arrangedSubviews
  2. On long press, add an overlay UIView as 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 the tempView— around (more on that in 4)
  3. Set the alpha of the arrangedSubview to 0 (setting hidden = true would result in the UIStackView animating closing in as if it were removed.
  4. Add a tempView to the overlay view (see 3) with the same initial frame as the arrangedSubview
  5. Drag the tempView up or down and insert/remove the actual arrangedSubview at a calculated index based on the position of the tempView.
  6. Listen for when the long press state is .Ended and set the arrangedSubview.alpha = 1 and 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?

like image 480
Clay Ellis Avatar asked Oct 16 '15 07:10

Clay Ellis


1 Answers

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.

like image 165
Clay Ellis Avatar answered Nov 02 '22 17:11

Clay Ellis