Reputation: 10129
I have a a number of pop up views saved as properties of a view controller. They are only added to the view when they are presented, and are removed from the view when they are hidden. Everything was working but i changed my code to simplify things and it's no longer working.
Here is an example of how I create and add my gesture recognizers:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];
The views are presented by a selector triggered by pressing a UIButton (there is normally other code in the if statements setting the custom view properties, but I cut it out for simplicity):
- (void)showPopUpView:(UIButton*)sender
{
CGRect endFrame = CGRectMake(10, 10, 300, 400);
UIView *popUpView;
if (sender == self.totalPowerInfoButton)
{
[self.view addSubview:self.totalPowerPopUpView];
popUpView = self.totalPowerPopUpView;
}
if (sender == self.co2LevelInfoButton)
{
[self.view addSubview:self.co2PopUpView];
popUpView = self.co2PopUpView;
}
[UIView animateWithDuration:0.5
animations:^ {
popUpView.alpha = 1.0;
popUpView.frame = endFrame;
}];
}
The popUpView's present, but the gesture recognizer selector doesn't get called when I tap them. Why not?
Upvotes: 0
Views: 720
Reputation: 1179
Double check and make sure the UIView you are adding the UIGestureRecognizer to has UserInteractionEnabled
set to YES
. i.e.
[self.imageView setUserInteractionEnabled:YES];
Upvotes: 1
Reputation: 3102
Does this work:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];
tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];
Upvotes: 4