views:

886

answers:

1

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];
}
A: 

I could image one possible solution:
Instead of hiding the view you could remove it from superview (and adding it again, when you need it). I think in this case the GestureRecognizer isn't active anymore.

Lars Petersen