0

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?

soleil
  • 12,133
  • 33
  • 112
  • 183

1 Answers1

0

Wouldn't:

self.theSubview.center = CGPointMake(self.theSubview.center.x + translation.x, 
                                     self.theSubview.center.y + translation.y);

Do the trick?

Martin Kenny
  • 2,468
  • 1
  • 19
  • 16