检测用户将项目拖出 UICollectionView? [英] Detect user dragging items out of UICollectionView?

查看:15
本文介绍了检测用户将项目拖出 UICollectionView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UICollectionView,我希望能够将项目向上和拖出视图,从而删除它们.(与 Dock 在 OS X 上的工作方式非常相似:拖出一些东西然后放开,然后它就会被移除).

I've got a UICollectionView, and I'd like to be able to touch-and-drag items up and out of the View, and thus delete them. (Very much along the same lines as how the Dock works on OS X: drag something off and let go, and it is removed).

我做了一些研究,但我发现的几乎所有东西都是在寻找可以拖放重新排序的 CollectionViews.我不需要重新排序(我很高兴从源数组中删除给定索引处的项目,然后重新加载),我只需要检测项目何时移出视图并释放.

I've done some research, but almost everything I find is looking for CollectionViews that are drag-and-drop to reorder. I don't need to reorder (I'm happy to just remove the item at the given index from the source array and then reload), I just need to detect when an item is moved outside of the View and released.

所以我想我的问题是:

1) 使用内置的 CollectionView、某种 itemWasDraggedOutsideViewFromIndex: 方法或其他方法可以实现吗?

1) Is that possible with the built-in CollectionView, some kind of itemWasDraggedOutsideViewFromIndex: method or something?

2) 如果不是,是否可以通过子类来完成(特别是对于 CollectionView 初学者来说是否可行)?

2) If not, is it something that can be done with a subclass (and specifically is it possible for a CollectionView beginner)?

3) 是否有任何代码示例或教程可以推荐来执行此操作?

3) Are there any code samples or tutorials you can recommend that do this?

推荐答案

这是我一直在研究的一个辅助类,它就是这样做的:实现:https://github.com/Ice3SteveFortune/i3-dragndrop,希望有帮助.有关于如何在 TestApp 中使用它的示例.

Here is a helper class that I've been working on that does just that: implementation: https://github.com/Ice3SteveFortune/i3-dragndrop, hope it helps. There's examples on how to use it in the TestApp.

更新

大约一年后,这是一个完整的拖放框架.希望这证明有用:https://github.com/ice3-software/between-kit

About a year on, this is now a full-on drag-and-drop framework. Hope this proves useful: https://github.com/ice3-software/between-kit

这篇关于检测用户将项目拖出 UICollectionView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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