0
votes

I have two UIScrollViews on my screen and I need to be able to drag a UIView from one scrollview to the other.

At the moment, I have a UILongGestureRecognizer on the UIView that I want to move, such that when the user starts dragging it, I make the view follow the touch:

- (void)dragChild:(UILongPressGestureRecognizer *)longPress {
    [[longPress view] setCenter:[longPress locationInView:[[longPress view] superview]]];
}

But when I get the boundary of the starting UIScrollView, the view disappears because it's locked into that scrollview's bounds.

Is there a way to "pop" it out of the scrollview when I start dragging such that I can carry it over to the other scrollview?

Also, how do I test for the "drop" location? I want to know if it's been dropped over a certain other view.

Or am I going about this all the wrong way?

Thanks guys

2

2 Answers

1
votes

If you will need to drag it from a scroll view to another do the following (pseudo code)

when you start dragging do the following

//scrollView1 is the scroll view that currently contains the view
//Your view is the view you want to move
[scrollView1.superView addSubView:yourView];

now when dropping the view, you will need to know if it is inside the other scrollview

//scrollView2 is the second scroll view that you want to move it too
//Your view is the view you want to move
CGPoint point = yourView.center;
CGRect rect = scrollView2.frame;
if(CGRectContainsPoint(rect, point))
{  
    //Yes Point is inside add it to the new scroll view
    [scrollView2 addSubView:yourView];
}
else
{
    //Point is outside, return it to the original view
    [scrollView1 addSubView:yourView];
}
0
votes

Here is an untested idea:

  • When the drag begins, move the dragging-view out of the scroll view (as a subview) and into the mutual superview of both scroll views.
  • When the drag ends, move the dragging-view out of the superview and into the new scroll view.

You'll probably have to be careful with coordinate systems, using things like [UIView convertPoint:toView:] to convert between the views' different perspectives when moving things around.