简体   繁体   English

IOS在滚动视图之间拖放

[英]IOS drag and drop between scroll views

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). 我有两个滚动视图,一个充满10个奇数子视图,基本上就像扑克牌(自定义类视图)。 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. ScrollView就像任何其他视图一样,所以它基本上是将视图从一个超级视图拖放到另一个超级视图。

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. 您的层次结构如下:您想要将视图V从视图A拖放到视图B.这意味着当您开始D&D时,V是A的子视图,当您完成时,V是B. A的子视图B必须有一个共同的超级视图S.

Steps: 0/ Your touch recognizer must be on S, not on A or B. 步骤:0 /您的触摸识别器必须在S上,而不是在A或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). 1 /用户点击V.你从A中删除它并将它添加到同一位置的S(UIView有方法将位置从视图转换到另一个视图)。
2/ User drags V to B. You change V's position in S. 2 /用户将V拖动到B.您在S中更改V的位置
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. 3 /用户下降V.如果它足够接近B,则将其插入B(转换位置S-> B)并设置位置之间的差异动画。 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. 如果它仍然接近A,则将其设置为A的动画。如果它位于A和B之间,您可以将其插入到最近的一个或让它停留在那里并阻止所有其他用户交互,直到用户再次点击V并将其拖入A或B.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM