iPhone/iOS: How to implement Drag and Drop for subviews of a Scrollview?

后端 未结 5 1202
盖世英雄少女心
盖世英雄少女心 2020-12-09 20:50

I am having an horizontal scrollview in an UIViewController, where i have many images in small sizes. I am keeping the images in scrollview because the images a

5条回答
  •  悲&欢浪女
    2020-12-09 21:17

    I did implement that behaviour before without any subclassing.

    I used canCancelContentTouches = NO of the UIScrollView to make sure the subviews handle there touches on their own. If a subview (in your case an image) was touched, i moved the view out of the scrollview onto the superview and started tracking it's dragging. (You have to calculate the correct coordinates within the new superview, so it stays in place).

    After dragging finishes, i checked if the target area was reached, otherwise I moved it back into the scrollview. If that's not detailed enough I could post some code.

    Well here is my example code: Github: JDDroppableView

提交回复
热议问题