0
votes

I'm adding subviews with tap gestures:

from UIView class(masterButton):

[self addSubview:self.button];

// Add gesture recognizers
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];

ViewController:

masterButton *button = [[masterButton alloc] initWithFrontImage:img ];

[self.view addSubview:button];

I removing the subview:

UIView * button= [controller.view viewWithTag:controller.tagButton]; [button removeFromSuperview];

The tap gesture it triggers to play audio file and works just fine but when I remove the subview and I tap the same area where the subview was it plays the audio like if the subview was there. How can I add the subview in a way were the main view is not responding to any gesture of the subviews?

I'm generating the subviews from UIview subclass and if I try to add the gesture like this:

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];

it doesn't work. any of you knows why?

I'll really appreciate your help.

3
How are you removing the subview. Post your codeEvol Gate
as your code shows you are adding gesturerecognizer to your view i think you should add it to your subview(button).[self.button addGestureRecognizer:.......]; [self.view add subview:self.button];Pratyusha Terli

3 Answers

2
votes

Add button like

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]]

[self.button removeFromSuperview];
0
votes

You are adding UITapGestureRecognizer to the mainview

Add UITapGestureRecognizer to self.button instead of self

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];
[self addSubview:self.button];
0
votes

just add Gesture to the masterButton like bellow..

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];