Sparklellama Sparklellama - 1 year ago 91
iOS Question

UIGestureRecognizer Delegate method is never called

Trying to make some draggable images in a subview of a scrollview. But nothing happens. Anybody got any ideas why a breakpoint in handlePan is never hit? :'( Thanks if u can help!

-(void) viewWillAppear:(BOOL)animated
twView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"twitter"]];
[self.springView addSubview:twView];
[twView setFrame:CGRectMake(100, 100, 60, 60)];

fbView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"facebook"]];
[self.springView addSubview:fbView];
[fbView setFrame:CGRectMake(200, 200, 60, 60)];

g1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[twView addGestureRecognizer:g1];
g1.delegate = self;

g2 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[fbView addGestureRecognizer:g2];
g2.delegate = self;


-(void)handlePan:(UIPanGestureRecognizer *)gesture
... do amazing things

Answer Source

Based on what you have here, it's probably one of two things. Either your image view doesn't have userInteractionEnabled set to yes, or there is another view on top of your image views blocking the gestures.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download