0

Is there any way to change the first responder halfway through a touch event?

I have a popover that should dismiss and resignFirstResponder if it recognizes a UIPanGesture. However, it still keeps the firstResponder until about a second later after it has started dismissing.

My goal is to "drag" a UIImageView out of the popover into the mainViewController. When the user drags a UIImageView in the popover, the popover should dismiss and a new UIImageView should be created in the mainControllerView that can be dragged around.

mainControllerView.m

-(IBAction)panGesture:(UIPanGestureRecognizer*)sender
{
    if (showPiecesPopover.isPopoverVisible) {
        [self.view removeGestureRecognizer:panGestureRecognizer];

        panGestureRecognizer = [((PopoverCreateNewBoardViewController*)showPiecesPopover.contentViewController) panGestureRecognizer];
        panGestureRecognizer.delegate = self;
        [self.view addGestureRecognizer:panGestureRecognizer];

        [showPiecesPopover dismissPopoverAnimated:YES];
    }
    if (movingPiece) {
        [selectedPieceImageView setCenter:[sender locationInView:self.view]];
    }
}

popover.m

-(void)viewWillAppear:(BOOL)animated
{
    panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:creatorViewController action:@selector(panGesture:)];
    [self.view addGestureRecognizer:panGestureRecognizer];
}

With this code the UIPanGestureRecognizer is called, but only for about a second due to the popover being dismissed as firstResponder. How do I change the firstResponder to the mainViewController's view?

On an unrelated note, the UIPanGestureRecognizer does not recognize a pan if the user does not move his fingers for a second then moves the fingers. Turning the recognizing simultaneous gestures on did not change anything

aeubanks
  • 1,261
  • 1
  • 12
  • 12
  • By the way, http://stackoverflow.com/questions/3148814/drag-n-drop-from-uipopovercontroller-to-other-uiview does not answer my question because it does not add a UIImageView to the mainViewController and allow it to handle the pan gestures. – aeubanks May 19 '13 at 13:10
  • Did you try sending becomeFirstResponder to the main view? – David H May 19 '13 at 13:40
  • Hmm... Now it works with the exact same code, with or without the becomeFirstResponder. But thanks, David! Now for the part where a pan is not recognized if the user holds his finger in one place then moves it. – aeubanks May 19 '13 at 14:22

0 Answers0