2

In iOS I am dragging a UIView between two parent UIViews. I am using UIPanGestureRecognizer to manage the dragging. While the dragging is still going on I switch the parent for the view being dragged by using:

- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender {
    ...
    [viewBeingDragged removeFromSuperview];
    UIView* page2 = [self.view viewWithTag:pageTag];
    [page2 addSubview:viewBeingDragged];
    // Now scroll page 2 into view
    [pageContainerScrollView setContentOffset:CGPointMake(xcoord, 0) animated:YES];
    ...

This seems to terminate the panning events. My finger however is still 'down'. At this point how can I detect my finger lifting up? I've tried a separate UITapGestureRecognizer which fires fine if panning is not occurring, but which does not fire if panning has started.

Any ideas?

Journeyman
  • 10,011
  • 16
  • 81
  • 129

2 Answers2

0

Try this:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        ...
    }

    UIPanGestureRecognizer *recognizer;
    recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];        
    [self addGestureRecognizer:recognizer];
}

And

-(void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {

    if ( [recognizer state] == UIGestureRecognizerStateEnded )
    {
        NSLog(@"Ended");
    }
}

You can find all the states here:

Hope it helps.

Mc-
  • 3,968
  • 10
  • 38
  • 61
0

I had the same problem. You just need to remove the line: [viewBeingDragged removeFromSuperview];.

A UIView can only have one superview, so when you call [page2 addSubview:viewBeingDragged] the viewBeingDragged UIView will first be removed from its current superview.

Community
  • 1
  • 1
Rich
  • 7,348
  • 4
  • 34
  • 54