UIStackView - 拖动以重新安排排列的子视图? [英] UIStackView - drag to reorder arranged subviews?

查看:183
本文介绍了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:


  1. 为每个 arrangeSubview s添加长按手势识别器

  2. 长按,添加覆盖 UIView 作为主视图的子视图,并填充整个主视图。这个叠加视图将作为各种各样的画布,因为我拖动临时重新排序视图 - 我们称之为 tempView - 围绕(更多关于4)

  3. 设置 arrangeSubview的 alpha 为0(设置 hidden = true 会导致 UIStackView 动画关闭,就像它被删除一样。

  4. tempView 添加到叠加层视图(参见3),其初始帧与 arrangeSubview

  5. 向上或向下拖动 tempView 并插入/删除实际 arrangeSubview 在基于 tempView 位置的计算索引处。

  6. 收听当长按 .Ended 并设置 arrangeSubview.alpha = 1 并从主视图中删除叠加层视图。

  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?

推荐答案

我已经创建了一个自定义控件来解决这个问题,可以找到这里

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆