IOS drag and drop between scroll views

前端 未结 1 1660
攒了一身酷
攒了一身酷 2020-12-30 13:13

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

相关标签:
1条回答
  • 2020-12-30 13:31

    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.

    0 讨论(0)
提交回复
热议问题