I’ve made a UIPanRecognizer like this.
- (void)pan:(UIPanGestureRecognizer *)gesture
{
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
CGPoint translation = [gesture translationInView:self];
self.origin = CGPointMake(
self.origin.x+translation.x,self.origin.y+translation.y);
[gesture setTranslation:CGPointZero inView:self];
}
}
But my view never gets redrawn, that means… my drawRect wont be called again. Anybody ever tried this?
In my viewController I have this
UIGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.graphView action:@selector(pan:)];
[self.graphView addGestureRecognizer:pan];
[self updateUI];
My updateUI is
- (void)updateUI { [self.graphView setNeedsDisplay]; }
You are calling your
updateUImethod when you attach the gesture recognizer to the view. You should be doing it in your callback methodpan:.Also, you are leaking memory. After allocating and adding the
UIGestureRecognizerto the view you shouldreleaseit.