UIStackView - 拖动以重新安排排列的子视图? [英] UIStackView - drag to reorder arranged subviews?
本文介绍了UIStackView - 拖动以重新安排排列的子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获得一些关于如何在 UITableView
上实现相同类型的拖动重新排序行为但在<$ c上的建议$ c> UIStackView 。
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:
- 为每个
arrangeSubview
s添加长按手势识别器 - 长按,添加覆盖
UIView
作为主视图的子视图,并填充整个主视图。这个叠加视图将作为各种各样的画布,因为我拖动临时重新排序视图 - 我们称之为tempView
- 围绕(更多关于4) - 设置
arrangeSubview的
为0(设置alpha
hidden = true
会导致UIStackView
动画关闭,就像它被删除一样。 - 将
tempView
添加到叠加层视图(参见3),其初始帧与arrangeSubview
- 向上或向下拖动
tempView
并插入/删除实际arrangeSubview
在基于tempView
位置的计算索引处。 - 收听当长按
州
是.Ended
并设置arrangeSubview.alpha = 1
并从主视图中删除叠加层视图。
- Add a long press gesture recognizer to each of the
arrangedSubview
s - 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 thetempView
— around (more on that in 4) - Set the
alpha
of thearrangedSubview
to 0 (settinghidden = true
would result in theUIStackView
animating closing in as if it were removed. - Add a
tempView
to the overlay view (see 3) with the same initial frame as thearrangedSubview
- Drag the
tempView
up or down and insert/remove the actualarrangedSubview
at a calculated index based on the position of thetempView
. - Listen for when the long press
state
is.Ended
and set thearrangedSubview.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?
推荐答案
我已经创建了一个自定义控件来解决这个问题,可以找到这里。
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.
这篇关于UIStackView - 拖动以重新安排排列的子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文