问题描述
所以这里是抓住。我有两个滚动视图,一个填充10个奇数子视图,基本上就像扑克牌(自定义类视图)。我想能够将这些视图拖放到我拥有的空滚动条上。这两个滚动视图之间有许多不同的视图。所以我想显示实际上从一个视图拖动并被放置在另一个滚动视图中的视图。我如何实现这一点。
我知道我必须使用触摸,但如果有人可以鞭打一个快速的例子,我会很棒。
谢谢。
它很简单。 ScrollView就像任何其他视图一样,它基本上是将视图从一个超级视图拖放到另一个超级视图。
您的层次结构如下所示:
您要拖动并将视图V从视图A放到视图B.这意味着当您启动D&D时,V是A的子视图,当您完成时,V是B的子视图.A和B必须有一个共同的超视图S.
步骤:
0 /您的触摸识别器必须在S上,而不是A或B。
1 /用户点击V。将其从A中删除并将其添加到同一位置的S(UIView具有将视图从视图转换到另一视图的方法)。
2 /用户拖动V到B.你改变V的位置。
3 /用户下降V.如果足够接近B,将其插入到B(转换位置S-> B),并动画位置之间的差异。如果它仍然接近A,将其动画回到A.如果它在A和B之间的某处,您可以将其插入到最近的一个,或者让它留在那里,并阻止所有其他用户的交互,直到用户再次点击V并拖动到A或B。
So here is the catch. I have two Scroll Views, one is filled with 10 odd subviews, that are basically like playing cards (custom class views). I want to be able to drag and drop some of these views to the empty scroll bar that i have.
There are many different views in between these two scroll views. So i want to show the view being actually dragged from one view and being placed in the other scroll view. How do i achieve this.
I know i have to use touches, but if anyone can whip up a quick example, i'll be greatful.Thanks.
Its very easy. ScrollView is like any other view so it's basically drag and drop a view from one superview to another superview.
Your hierarchy is the following:You want to drag and drop a view V from a view A to a view B. That means that when you start D&D, V is subview of A and when you finish, V is subview of B. A and B must have a common superview S.
Steps:0/ Your touch recognizer must be on S, not on A or B.
1/ User taps on V. You remove it from A and add it to S on the same position (UIView has methods to transform position from a view to another view).
2/ User drags V to B. You change V's position in S.
3/ User drops V. If it's close enough to B, insert it to B (transforming position S->B) and animate the difference between positions. If it's still close to A, animate it back to A. If it's somewhere between A and B you can either insert it to the nearest one or let it stay there and block all other user interaction until user tap V again and drags it into A or B.
这篇关于IOS在滚动视图之间拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!