Adding a UITapGestureRecognizer to a view then removing seems to short circuit button events
Posted
by heymon
on Stack Overflow
See other posts from Stack Overflow
or by heymon
Published on 2010-05-29T21:46:40Z
Indexed on
2010/05/29
21:52 UTC
Read the original article
Hit count: 451
In the code below I am popping up a ImageView as the result of a users touchUpInside on a simple info button. There are other buttons on the view.
To dismiss the info I added a UITapGestureRecognizer to my controllers view, and hide the view when the tap is detected.
If I don't remove the tapGestureRecognizer, the action is called every time some.
Even when I do remove the gesture action, no bottons receive touchUpInside events once this gesture recognizer is added. Why?
Code from my MainViewController
(void) dismissInfo: (UITapGestureRecognizer *)gesture { [kInfoView setHidden: YES]; [gesture removeTarget: self action: NULL]; }
(IBAction) displayInfo {
CGRect startFrame = CGRectMake(725, 25, 0, 0), origFrame; CGFloat yCenter = [kInfoView frame].size.height/2 + 200; CGPoint startCenter = CGPointMake(724, 25), displayCenter = CGPointMake(384, yCenter); UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(dismissInfo:)];
[self.view addGestureRecognizer: g]; origFrame = [kInfoView frame]; [kInfoView setCenter: startCenter]; [kInfoView setHidden: NO]; [kInfoView setFrame: startFrame];
[UIView beginAnimations: @"info" context: nil]; [UIView setAnimationDuration: .5]; [UIView setAnimationDelegate: self];
[kInfoView setFrame: origFrame]; [kInfoView setCenter: displayCenter];
[UIView commitAnimations]; }
© Stack Overflow or respective owner