The following creates a gesture recognizer that moves the entire view:
UIPanGestureRecognizer * recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
recognizer.delegate = self;
[self.view addGestureRecognizer:recognizer];
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
But I want to just move one of the subviews. I can't just do this:
[self.theSubview addGestureRecognizer:recognizer];
because I want to recognize gestures on the entire screen. The object that should move could be small and I don't want to force the user to "grab" it. How can I modify the handler method to just move theSubview?