UIStackView - drag to reorder arranged subviews?

前提是你 提交于 2019-12-06 01:48:29

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!