i know how to add a gesture recognizer via the IB but I’m trying to figure it out with out using IB.
So basically what have right now is
blue1.userInteractionEnabled = YES;
UIPanGestureRecognizer *pgr = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePan:)];
[blue1 addGestureRecognizer:pgr];
[pgr release];
and my handlePan is
-(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];
}
this works fine if i do it over the IB and i am able to movie the piece around.
I dont understand what is causing it not to move like it is coded now.
Any help is appreciated.
I also tried -(void) instead of -(IBAction) in my handlePan but that didn’t work either.
The fact that this works in IB, but not in code suggests that the error is in the first block of code. My suspicion would be that
blue1isnil. Make sure that you do not try to modify views beforeviewDidLoad. They will all benilininitWithFrame:andawakeFromNib.